Programs are an abstraction over items, that have a dedicated result, and form an async monad.
You will usually start with an item that allows some user interactions when the program is 'running', like
(c/defn-item my-form [running?]
(dom/button {:disabled (not running?)
:onClick (fn [v _] (c/return :action "done"))}))
Then define a program that runs that
(defn-program my-program []
[res (await-action my-form)]
(show (dom/div res)))
And then add running this program into your application
(dom/div "My program:" (runner (my-program)))
Programs are an abstraction over items, that have a dedicated result, and form an async monad. You will usually start with an item that allows some user interactions when the program is 'running', like ``` (c/defn-item my-form [running?] (dom/button {:disabled (not running?) :onClick (fn [v _] (c/return :action "done"))})) ``` Then define a program that runs that ``` (defn-program my-program [] [res (await-action my-form)] (show (dom/div res))) ``` And then add running this program into your application ``` (dom/div "My program:" (runner (my-program))) ```
(await-action f & [pred])
A program that shows the item returned by (f running?)
, until it
emits an action where the given predicate holds, which is then
returned as the programs result. If no predicate is specified, then
any action will be taken as the result of the program.
A program that shows the item returned by `(f running?)`, until it emits an action where the given predicate holds, which is then returned as the programs result. If no predicate is specified, then any action will be taken as the result of the program.
(await-state f & [done-state?])
A program that shows the item returned by (f running?)
, until
its state is a non-nil value, or the given predicate holds,
returning that value as the program's result.
A program that shows the item returned by `(f running?)`, until its state is a non-nil value, or the given predicate holds, returning that value as the program's result.
(defn-program name params & body)
A macro just like defn
, but where the body is wrapped in do-program
.
A macro just like `defn`, but where the body is wrapped in [[do-program]].
(do-program form & forms)
A monadic do notation for programs.
For example:
(do-program
[r1 (return 21)]
(return (* r1 2)))
A monadic do notation for programs. For example: ``` (do-program [r1 (return 21)] (return (* r1 2))) ```
(fmap f program)
A program that applies f to the result of the given program.
A program that applies f to the result of the given program.
(race program & programs)
A program running several programms in parallel, until the first one is finished, returning the result of that 'winner'.
A program running several programms in parallel, until the first one is finished, returning the result of that 'winner'.
(return v)
A program that immediately returns the given value once when run.
A program that immediately returns the given value once when run.
(runner program & [handle-result-f])
An item that runs the given program once, offering an event handler for handling the result of the program.
An item that runs the given program once, offering an event handler for handling the result of the program.
(sequ program & programs)
A program consisting of several programs run one after the other, returning the result of the last one.
A program consisting of several programs run one after the other, returning the result of the last one.
(show item)
A program that just shows the given item, but never completes.
A program that just shows the given item, but never completes.
(sleep ms)
A program that returns nil
after the given number of milliseconds
have elapsed.
A program that returns `nil` after the given number of milliseconds have elapsed.
(then program cont)
A program that runs program
first, and then the program (cont result)
, where result
is the result of the first program.
A program that runs `program` first, and then the program `(cont result)`, where `result` is the result of the first program.
(trampoline program)
A trampoline can be used to make programs that use mutual recursion run without consuming any stack or heap, thus can potentially run forever. This returns a program that runs the given program until it returns. If it returns another program, then the execution is continues with that program. If it returns something else, then the program completes.
A trampoline can be used to make programs that use mutual recursion run without consuming any stack or heap, thus can potentially run forever. This returns a program that runs the given program until it returns. If it returns another program, then the execution is continues with that program. If it returns something else, then the program completes.
(wrap f program)
A program wrapped in some additional markup, via (f item)
, where
item
is the item representing the program in either the running or
the non-running state.
A program wrapped in some additional markup, via `(f item)`, where `item` is the item representing the program in either the running or the non-running state.
(wrap* f program)
A program wrapped in some additional markup, via (f item running?)
,
where item
is the item representing the program, and running?
a
boolean specifying if the program is in the running state or not.
A program wrapped in some additional markup, via `(f item running?)`, where `item` is the item representing the program, and `running?` a boolean specifying if the program is in the running state or not.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close