funcool

A channel for discussing and asking questions about Funcool libraries https://github.com/funcool/
2016-03-03T12:30:50.000037Z

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 ?

2016-03-03T12:31:43.000041Z

Also, unrelated but I asked a question there : http://stackoverflow.com/q/35770498/1327651

2016-03-03T13:05:33.000044Z

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]))

2016-03-03T16:27:15.000045Z

@nha: i suspect that docs are out of sync, i believe it was renamed to maybe-context

2016-03-03T16:28:05.000046Z

Probably a doc thing, yes.

2016-03-03T16:28:11.000047Z

I don't see maybe-context though

2016-03-03T16:28:16.000048Z

@nha: it's cats.monad.maybe/context, sorry https://github.com/funcool/cats/blob/master/src/cats/monad/maybe.cljc#L170

2016-03-03T16:28:25.000051Z

Ah thanks :simple_smile:

2016-03-03T16:28:36.000052Z

and about the mapping

2016-03-03T16:28:48.000053Z

take into account that fmap "peels" one layer of monadic context

2016-03-03T16:29:02.000054Z

so in the example

(fmap inc (just [1 2 3]))

2016-03-03T16:29:13.000055Z

will try to apply inc to [1 2 3]

2016-03-03T16:29:14.000056Z

thus failing

2016-03-03T16:29:22.000057Z

ah I see. (inc [ 1 2 3])

2016-03-03T16:29:25.000058Z

ok :simple_smile:

2016-03-03T16:29:26.000059Z

you can combine maybe and sequence functors

2016-03-03T16:29:37.000060Z

and map over nested vectors inside maybe or viceversa

2016-03-03T16:29:49.000061Z

although having many layers can get hairy

2016-03-03T16:30:04.000062Z

(fmap #(map inc %) (just [1 2 3])) may be simpler

2016-03-03T16:31:49.000063Z

Right thanks :simple_smile:

2016-03-03T16:34:58.000064Z

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)

2016-03-03T17:13:25.000065Z

you mean for example transforming Future[A] into A?

2016-03-03T17:13:45.000066Z

in Clojure you can dereference futures and the thread will block until available (timeout is optional)

2016-03-03T17:13:56.000067Z

(deref some-future)