Skip to content

Instantly share code, notes, and snippets.

@taojang
Created May 26, 2016 09:18
Show Gist options
  • Save taojang/cbf711ab389bbe0e25d6ecf9a804d509 to your computer and use it in GitHub Desktop.
Save taojang/cbf711ab389bbe0e25d6ecf9a804d509 to your computer and use it in GitHub Desktop.
hello-cats
(ns hello-cats.core
(:require [cats.core :as m :refer [mlet]]
[cats.monad.either :as either]
[cats.monad.maybe :as maybe]
[cats.monad.identity :as id]
[cats.context :as ctx]
[cats.builtin :refer [sum-monoid prod-monoid vector-context]])
(:gen-class))
(defn m-mappend
[semigrp-ctx mx my]
(mlet [x mx
y my]
(m/return
(ctx/with-context semigrp-ctx
(m/mappend x y)))))
(comment
(m-mappend sum-monoid (maybe/just 1) (maybe/just 2)) ; => #<Just 3>
(m-mappend sum-monoid (either/right 1) (either/left "oops")) ; => #<Left "oops">
(m-mappend sum-monoid [1 2 3 4] [5 6]) ; => [6 7 7 8 8 9 9 10]
(m-mappend prod-monoid [1 2 3 4] [5 6]) ; => [5 6 10 12 15 18 20 24]
)
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment