Skip to content

Instantly share code, notes, and snippets.

@otfrom
Created February 19, 2018 17:09
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 otfrom/60b9f9fa7c3f345710aa894fca83771c to your computer and use it in GitHub Desktop.
Save otfrom/60b9f9fa7c3f345710aa894fca83771c to your computer and use it in GitHub Desktop.
How I learned core.async
(ns otfrom.copper
(:require [clojure.core.async :as a]))
(def tenner (a/chan))
(def mten (a/mult tenner))
(def t1 (a/tap mten (a/chan)))
(def t2 (a/tap mten (a/chan)))
(def r1 (a/reduce (fn [a n]
(println "r1 a: " a " n: " n)
(+ a n))
0
t1))
(def r2 (a/reduce (fn [a n]
(println "r2 a: " a " n: " n)
(* a (inc n)))
1
t2))
(a/pipe (a/to-chan (range 10)) tenner)
(a/<!! r1)
(a/<!! r2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment