You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Firstly I just want to say that I love this library and has allowed to me to largely remove my own custom implementation of a lot of these types. However I was wondering what the reasoning behind the signature and behaviour of (mo.Option).Map?
Generally speaking Map called on a Some should always return a Some which is a sentiment you also shared here. The ability to return false within the mapper makes Map behave more like FlatMap. It also makes passing point-free functions a little awkward as you have to "lift" the mapper into that signature. e.g.
// Error function signature requires returning an additional booleanmo.Some("ExampleString").Map(strings.ToLower)
funclift[Aany](fnfunc(A) A) func(A) (A, bool) {
returnfunc(aA) (A, bool) {
returnfn(a), true
}
}
mo.Some("ExampleString").Map(lift(strings.ToLower))
I propose that (mo.Option).Map's signature should be changed to remove the boolean argument, if someone wants the old behaviour they can use FlatMap and TupleToOption.
The text was updated successfully, but these errors were encountered:
DylanRJohnston-FZ
changed the title
Weird function signature on (*mo.Option).Map
Weird function signature on (mo.Option).MapMar 20, 2023
Firstly I just want to say that I love this library and has allowed to me to largely remove my own custom implementation of a lot of these types. However I was wondering what the reasoning behind the signature and behaviour of
(mo.Option).Map
?Generally speaking
Map
called on aSome
should always return aSome
which is a sentiment you also shared here. The ability to returnfalse
within themapper
makesMap
behave more likeFlatMap
. It also makes passing point-free functions a little awkward as you have to "lift" the mapper into that signature. e.g.I propose that
(mo.Option).Map
's signature should be changed to remove the boolean argument, if someone wants the old behaviour they can useFlatMap
andTupleToOption
.The text was updated successfully, but these errors were encountered: