Liking cljdoc? Tell your friends :D

reacl-c-basics.programs.core

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)))
```

raw docstring

await-actionclj/s

(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.
sourceraw docstring

await-stateclj/s

(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.
sourceraw docstring

defn-programclj/smacro

(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]].
sourceraw docstring

do-programclj/smacro

(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)))
```
sourceraw docstring

fmapclj/s

(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.
sourceraw docstring

parclj/s

(par & programs)
source

program?clj/s

(program? v)

A predicate for programs.

A predicate for programs.
sourceraw docstring

raceclj/s

(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'.
sourceraw docstring

returnclj/s

(return v)

A program that immediately returns the given value once when run.

A program that immediately returns the given value once when run.
sourceraw docstring

runnerclj/s

(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.
sourceraw docstring

sequclj/s

(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.
sourceraw docstring

showclj/s

(show item)

A program that just shows the given item, but never completes.

A program that just shows the given item, but never completes.
sourceraw docstring

sleepcljs

(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.
sourceraw docstring

thenclj/s

(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.
sourceraw docstring

trampolineclj/s

(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.
sourceraw docstring

wrapclj/s

(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.
sourceraw docstring

wrap*clj/s

(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.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close