/
api.clj
65 lines (55 loc) · 1.81 KB
/
api.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ns state-flow.api
"This namespace provides the user API, that is, the set of public functions that one can use for writing flows."
(:refer-clojure :exclude [for when])
(:require [cats.core :as m]
[state-flow.assertions.matcher-combinators]
[state-flow.cljtest]
[state-flow.core]
[state-flow.state]
[state-flow.vendor.potemkin :refer [import-fn import-vars]]))
;; TODO: (dchelimsky,2020-05-18) Intellij / Cursive doesn't recognize the
;; vars imported below unless we declare them. If that is ever fixed, we
;; should remove this.
(declare flow
run
run*
log-and-throw-error!
ignore-error
invoke
return
fmap
defflow
match?
get-state
swap-state
when)
(import-vars
state-flow.core/flow
state-flow.core/run
state-flow.core/run*
state-flow.core/log-and-throw-error!
state-flow.core/ignore-error
state-flow.state/invoke
state-flow.state/return
state-flow.state/fmap
state-flow.state/when
state-flow.cljtest/defflow
state-flow.assertions.matcher-combinators/match?)
(import-fn state-flow.state/gets get-state)
(import-fn state-flow.state/modify swap-state)
;; NOTE: this could be imported directly from cats.core, but we're defining
;; it here to keep the documentation in terms of state-flow rather than cats.
(defmacro for
"Like clojure.core/for, but returns a flow which wraps a sequence of flows e.g.
(flow \"even? returns true for even numbers\"
(flow/for [x (filter even? (range 10))]
(match? even? x)))
;; same as
(flow \"even? returns true for even numbers\"
(match? even? 0)
(match? even? 2)
(match? even? 4)
(match? even? 6)
(match? even? 8)) "
[seq-exprs flow]
`(m/for ~seq-exprs ~flow))