core.when
0.000001

Calls a composition for truthy input.

Arguments
procrequired
The composition to execute for truthy inputs.
Return Value
The result of the given composition, or null if the input is falsey.
something went wrong :(
Conditionally echoing a value
Setup
authorization=PROCAUTH
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
client.core.when {
  client.core.echo("is true")
}.call(true)
client.core.when(undefined, {}, () => {
  return client.core.echo("is true");
}).call(true);
curl "https://proc.run/core/when" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[[">>", ["%%", true]], ["$$", "proc", ["{}", ["()", "core.echo", [">>", ["%%", "is true"]]]]]]'
 

is true

Note that core.when cannot be composed with core.else. Prefer core.when to core.if for use-cases where you do not have a corresponding call to core.else—it helps communicate intent.


Stuck? Want to chat about an idea? Join the community on Discord.