Hacker News new | ask | show | jobs
by blastonico 488 days ago
> The method names are more intuitive: e.g., then instead of map

But map makes total sense, considering that maybe is a monad.

5 comments

Rather than monads, map is more likely to be familiar from sequences, and an optional is just a sequence with length < 2.
Well, monads get their map from functors, and they call it 'map' (or fmap) because of map on sequences.
I would expect different types of map and then:

    map :: (a -> b) -> Maybe a -> Maybe b
    then :: (a -> Maybe b) -> Maybe a -> Maybe b
Although for Maybe these are not too different.
“then” is definitely less intuitive
Intuition is in the eye of the beholder
Well, it only needs to be a functor (in the Haskell sense) for map to make sense.

(Of course, all monads are also functors.)

True, but I would not be surprised if the vast majority of Java programmers have no clue what a monad is.
> no clue what a monad is.

which is a good opportunity to introduce said nomenclature, and ideas to them, rather than renaming said method to something more "palatable".

In my experience just name-dropping monads in non functional-programming oriented circles will get weird looks.

EDIT: I would even argue, as a fan of FP, that it's not immediately obvious how this terminology or concept even helps, from the point of view of a non purely functional programming language

Because the alternative to using one name is using more than one name. These days I'm pretty sure I'm using `select` to mean `map`.
You don’t need to mention monads, just imagine an Optional as a list with at most one element.