At the end of http://funcool.github.io/cats/latest/#applicative there is :
(require '[cats.monad.maybe :as maybe])
(pure maybe/maybe-monad 5)
;; => #<Just 5>
has maybe-monad
been removed ?Is it maybe
now? : https://github.com/funcool/cats/blob/master/src/cats/monad/maybe.cljc#L304
Also, unrelated but I asked a question there : http://stackoverflow.com/q/35770498/1327651
also, why do these don't work, given that (just [1 2 3]) is a wrapped value ?
(fmap inc (just [1 2 3]))
(fmap inc (map just [1 2 3]))
@nha: i suspect that docs are out of sync, i believe it was renamed to maybe-context
Probably a doc thing, yes.
I don't see maybe-context
though
@nha: it's cats.monad.maybe/context
, sorry https://github.com/funcool/cats/blob/master/src/cats/monad/maybe.cljc#L170
Ah thanks :simple_smile:
and about the mapping
take into account that fmap
"peels" one layer of monadic context
so in the example
(fmap inc (just [1 2 3]))
will try to apply inc
to [1 2 3]
thus failing
ah I see. (inc [ 1 2 3])
ok :simple_smile:
you can combine maybe and sequence functors
and map over nested vectors inside maybe or viceversa
although having many layers can get hairy
(fmap #(map inc %) (just [1 2 3]))
may be simpler
Right thanks :simple_smile:
just out of curiosity (as I think I remember you do scala), is there an equivalent of their flatten that resolves async values (note : I don't do scala so I may be wrong about that)
you mean for example transforming Future[A]
into A
?
in Clojure you can dereference futures and the thread will block until available (timeout is optional)
(deref some-future)