jasonkuhrt-archive / maybe

Correct implementation of the Maybe monad in JavaScript
1 stars 0 forks source link

Add additional functions #3

Open jasonkuhrt opened 10 years ago

jasonkuhrt commented 10 years ago

As seen from here:

http://hackage.haskell.org/package/base-4.6.0.1/docs/Data-Maybe.html#t:Maybe

We're still missing:

                        AKA in haskell
Maybe.map_maybe         mapMaybe
Maybe.cat_maybes        catMaybes
Maybe.maybe_to_list     maybeToList
Maybe.list_to_maybe     listToMaybe

It would be nice to know/have a use-case for each before blindly porting them. the map use-case is exemplified in e.g. http://www.youtube.com/watch?v=m3svKOdZijA

Consider that we probably want to omit maybe terms in function names given that we're invoking from the Maybe namespace:

                  AKA in haskell
Maybe.map         mapMaybe
Maybe.cat         catMaybes
Maybe.to_list     maybeToList
Maybe.list_to     listToMaybe
jasonkuhrt commented 10 years ago

Renaming as such would be incorrect

                  AKA in haskell
Maybe.map         mapMaybe
Maybe.cat         catMaybes
Maybe.to_list     maybeToList
Maybe.list_to     listToMaybe

Because e.g. Maybe.map is reserved for the Functor notion of map which is different from what is intended by maybe_map:

The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it just Just b, then b is included in the result list.