Created
April 24, 2019 22:11
-
-
Save mynomoto/084c640ef90c333861a1ab71e9688b36 to your computer and use it in GitHub Desktop.
Sample of using funcool/cats {:mvn/version "2.3.2"}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns kondo.cats | |
(:require | |
[cats.core :as m] | |
[cats.monad.either :refer [left left? right right?]])) | |
(defn assoc-b | |
[m v] | |
(right (assoc m :b v))) | |
(defn merge-2 | |
[m m1 m2] | |
(right (merge m m1 m2))) | |
(defn thread-first | |
[] | |
(m/->= (right {}) | |
(#(right (assoc % :a :b))) | |
(assoc-b :c) | |
(merge-2 {:c :d} {:d :e}))) | |
(defn assoc-b-last | |
[v m] | |
(right (assoc m :b v))) | |
(defn thread-last | |
[] | |
(m/->>= (right {}) | |
(#(right (assoc % :a :b))) | |
(assoc-b-last :c) | |
(merge-2 {:c :d} {:d :e}))) | |
(defn thread-as | |
[] | |
(m/as->= (right {}) xxx | |
(#(right (assoc % :a :b)) xxx) | |
(assoc-b-last :c xxx) | |
(merge-2 xxx {:c :d} {:d :e}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment