This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-02
Channels
- # admin-announcements (29)
- # aws (11)
- # beginners (247)
- # boot (11)
- # business (1)
- # cider (73)
- # clara (5)
- # cljs-dev (37)
- # cljsrn (29)
- # clojure (86)
- # clojure-dev (9)
- # clojure-indonesia (1)
- # clojure-italy (3)
- # clojure-nl (1)
- # clojure-russia (195)
- # clojure-sg (2)
- # clojure-uk (3)
- # clojurecup (1)
- # clojurescript (296)
- # clojurex (2)
- # code-reviews (6)
- # core-async (3)
- # cursive (33)
- # datavis (9)
- # datomic (11)
- # funcool (31)
- # hoplon (1)
- # ldnclj (8)
- # lein-figwheel (5)
- # leiningen (5)
- # luminus (4)
- # off-topic (3)
- # om (172)
- # onyx (13)
- # re-frame (5)
- # reagent (84)
Is it just me or is there no convenience functions to create Maybe
or Either
from something potentially nullable?
Basically something like this:
(let [result (something-that-might-return-null ...)]
(if result
(just result)
(nothing)))
And that's quite verbose and I was wondering if I was missing a convenience function that could encapsulate that
(and something analogous for Either
where you would specify the Left
value if the result was nil
)
Well, I partly agree that Either is more semantically rich than Maybe
here and there's more reason to handle both Right
and Left
by hand
the cats.monad.exception already provides a "Either" analogous abstraction just for succes and failure and also provides a try-on
macro that allows easy wrap any result in a proper type
note that nil
already participates in the Maybe abstraction, is equivalent to Nothing
Since you already have maybe/from-maybe
then maybe to-maybe
or from-nullable
could be a good choice as well?
I've opened an issue to not forget about it https://github.com/funcool/cats/issues/133