Add flatMap operator to Options#6404
Conversation
|
I would personally prefer a name, like |
|
@zielmicha I associate |
|
I know it from Scala as I would probably prefer |
|
@bluenote10 : 👍 on the |
|
@subsetpark You are right that I would now vote for |
|
@bluenote10 my issue with |
|
I'm fine with |
0357d5c to
94d0ed3
Compare
|
|
||
| proc `$`*[T]( self: Option[T] ): string = | ||
| proc `$`*[T](self: Option[T]): string = | ||
| ## Returns the contents of this option or `otherwise` if the option is none. |
There was a problem hiding this comment.
The comment on this proc seems a little misleading, might as well update it whilst you've got a PR touching the code anyway I reckon.
|
Nim is not Haskell, no '>>=' please. That could also be "shift right assign". |
|
@Araq do you like flatMap as well? |
|
'flatMap' too means nothing. Can we come up with a name that says something? |
|
@Araq, I guess that non-fp guys use nillable types, and fp guys know what is We can't call it There is another, but less well known name for this operation - |
|
Actually, I always found the name |
|
It could be |
|
I guess that the better decision is to separate standard library from FP library. The |
I agree with @bluenote10 and I would say that is hard to make a name that has more meaning. It is literally
|
|
I'm of the opinion that But anyhow - much more strongly than believing against To that same point I would hesitate to make How do we resolve this? |
dom96
left a comment
There was a problem hiding this comment.
Small nit but otherwise good to go.
lib/pure/options.nim
Outdated
| else: | ||
| result = none(int) | ||
|
|
||
| check( some(1).flatMap(addOneIfNotZero) == some(2) ) |
There was a problem hiding this comment.
Nit: This spacing inside the parenthesis should be removed.
|
@vegansk Seems compatible with what is written here, isn't it? |
|
@andreaferretti , @subsetpark sorry, I read it wrong :-( |
|
@andreaferretti @vegansk now you guys have me really confused... the last line in @vegansk 's example is not compatible with the current implementation, which only goes |
|
What further muddies the waters is that https://stackoverflow.com/questions/22511483/understanding-option-flatten-in-scala#22511696 seems to indicate that |
|
The thing is, Now, you may object that the compiler has no way to detect that that particular instance of It is probably an error in the scala implementation. Since algebraic data types are implemented with inheritance (that is Your implementation is fine :-) |
* Add >>= operator to Options * options.bind callback signature: A -> Option[B] * Use `flatMap` as the name of the Option bind operation. * Rename Options test "bind" to "flatMap" * CR from @dom96: Remove spaces inside of check() call
Adds the monadic bind operator to the options module.