Skip to content

Instantly share code, notes, and snippets.

@mynomoto
Created Apr 24, 2019
Embed
What would you like to do?
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