core.else
0.000001

Defines an else branch of logic for a corresponding if statement.

Arguments
procrequired
The composition to execute when the branch is matched.
Return Value
The result of the given composition if the else branch is matched, or null.
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");
composition = client.core.if {
  client.core.echo("is true")
} >> client.core.else {
  client.core.echo("is false")
}

composition.call(false)
let composition = client.core.if(undefined, {}, () => {
  return client.core.echo("is true");
}).compose(
  client.core.else(undefined, {}, () => {
    return client.core.echo("is false");
  }
);

composition.call(false);
curl "https://proc.run/core/exec" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "proc", ["{}", ["()", "type.string"], ["()", "type.string.append", [">>", ["%%", "hello"]]]]]]'
 

is false

Note that core.else can only be composed with core.if.


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