Re:Elm 0.15: Asynchrony with Tasks
by dragonwriter on Monday April 20, 2015 @08:11PM
(#9411604)
> Absence of applicatives or monads mean that you have to explicitly pattern match on Just/Nothing everytime.
It seems to me that most real uses can probably be solved by map, and withDefault if you really need to get out of the Maybe monad for some reason (though map should make it so that you don't have to for most things.)
> There is a proposal to add `?` as an operator to obtain the head of the list without the Maybe and provide a default value if it is Nothing.
Since elm supports user-defined operators, can't you just do that yourself. Something like:
list ? default = withDefault default (head list)Yep! The proposal is to add that to the core libraries, and is basically just waiting to see how much people actually want to use withDefault that way in practice.
There's already withDefault to make that concise, so you can do things like this:
withDefault 0 (head listOfNumbers)
No need to pattern match every time. :)Docs for withDefault: http://package.elm-lang.org/packages/elm-lang/core/1.0.0/May...
Re:Elm 0.15: Asynchrony with Tasks
by RehnoLindeque on Tuesday April 21, 2015 @06:37AM
(#9413155)
I've defined (?) in http://package.elm-lang.org/packages/circuithub/elm-maybe-ex... in the mean time.
Absence of applicatives or monads mean that you have to explicitly pattern match on Just/Nothing everytime. There is a proposal to add `?` as an operator to obtain the head of the list without the Maybe and provide a default value if it is Nothing. Also there is another proposal to allow `unsafe` for the program to crash if the result is Nothing.