Skip to content

Instantly share code, notes, and snippets.

@mynomoto
Created April 24, 2019 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mynomoto/084c640ef90c333861a1ab71e9688b36 to your computer and use it in GitHub Desktop.
Save mynomoto/084c640ef90c333861a1ab71e9688b36 to your computer and use it in GitHub Desktop.
Sample of using funcool/cats {:mvn/version "2.3.2"}
(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