Adding traverse to List, Option, Either and Tuple2#80
Conversation
|
FWIW, this is specifically |
|
@tonymorris Oops...i totally did not see that. I agree that it's a list traverse. |
|
Yeah no worries. You'll probably want the others some day too! |
|
@tonymorris sure thing 👍 |
|
@tonymorris and @amarpotghan Given the use of different applicatives, is the best way to handle this to represent the function on a traversable type t as: Some other classes this would apply to that I use: IO(?), SafeIO, Seq, Set(?), Stream, P1, Validation<A, _>, State<S, _>. This of course is starting to create alot of combinations, but it would be good to agree on the approach and fill in the missing implementations at some future point. |
|
Yep that's the problem. You have NxM instances to write where:
Given the limitations of Java's type system against the intractability of this problem, Functional Java has had a history of, "just pick the most common ones that I have the energy to write today." |
|
Consequently, I cannot speak for the energy of @amarpotghan. |
|
For TODO things, we should create Github issues. We can decide what we want to do for traverse here and then create an issue documenting what is left to do. I had a look at doing this for the Option type last night (so don't worry about Option). BTW, I also had a look at the laws that traversal had to comply with, but only really understood the identity law. I suspect this won't be a barrier to writing the code. |
|
@mperry Thanks. I will not touch |
|
No problem. FYI, I started reviewing these changes, but have not had time to finish yet. I will try to do some more tonight. |
|
@mperry thanks |
There was a problem hiding this comment.
I commented above that you were traversing over the left value and here you are traversing over the right value. I did not think you would do both. Is there a conflict here for the compiler in calls to traverseList(z -> ...)? Should this be renamed to traverseLeftList/traverseRightList?
There was a problem hiding this comment.
@mperry both resides on two different classes, i.e RightProjection and LeftProjection. client has to specify which projection he has to traverse, e.g e.right().traverseList(z -> ...). I think we should have traverseLeftList and traverseRightList in Either class.
There was a problem hiding this comment.
I have added translators for other applicatives too. Just worried if we really want to provide this convenience. I mean e.right().traverseList(z -> ...) is almost as good as e.traverseListRight(z -> ..)
There was a problem hiding this comment.
Ok, from the diffs I did not realise this was on the left and right projection. This is fine as is then.
There was a problem hiding this comment.
I would suggest to rename these variables, e.g. on line 372 as represent Option<List<B>>. Why not use obs or olb here? Same with the map2Option method.
There was a problem hiding this comment.
agreed!, you will see that changed soon!
|
I have had enough for now. Will check back tomorrow. Thanks for your hard work, it is much appreciated. |
|
|
There was a problem hiding this comment.
Do we need the hamcrest dependency when we are just saying the two lists are equal? I can't find a dependency to hamcrest currently. Am I missing something or is this a new dependency?
There was a problem hiding this comment.
Junit has it since a long ago
|
I think we are almost done. Just the hamcrest issue and either javadoc to address. |
|
Still places in the javadoc that mention fail, particularly for Either. Go to the "files changed" tab in this PR and search for "fail". We are almost there... |

No description provided.