Arguments
Compositions can define arguments that accept dynamic values.
Arguments are named placeholders that take the place of an input or argument value in a composition or stored proc. When called, values must be provided for each argument or an error is returned.
something went wrong :(
Truncating a string to a dynamic length
Setup
require "proc"
client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
truncate = client.type.string.truncate(
length: client.argument(:length)
) >> client.type.string.append(
value: "..."
)
truncate.call("hello", length: 3)
let truncate = client.type.string.truncate(
undefined, {length: client.argument("length")}
).compose(
client.type.string.append(
undefined, {value: "..."}
)
);
truncate.call("hello", {length: 3});
curl "https://proc.run/core/exec?length=3" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "proc", ["{}", [">>", ["%%", "hello"]], ["()", "type.string.truncate", ["$$", "length", ["@@", "length", {}]]], ["()", "type.string.append", ["$$", "value", ["%%", "..."]]]]]]'
hel...
Default Values
Arguments can define a default value used when the caller does not provide a value.
something went wrong :(
Truncating a string to a default length
Setup
require "proc"
client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
truncate = client.type.string.truncate(
length: client.argument(:length, default: 1)
) >> client.type.string.append(
value: "..."
)
truncate.call("hello")
let truncate = client.type.string.truncate(
undefined, {length: client.argument("length", {default: 1})}
).compose(
client.type.string.append(
undefined, {value: "..."}
)
);
truncate.call("hello");
curl "https://proc.run/core/exec" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "proc", ["{}", [">>", ["%%", "hello"]], ["()", "type.string.truncate", ["$$", "length", ["@@", "length", {"default": ["%%", 1]}]]], ["()", "type.string.append", ["$$", "value", ["%%", "..."]]]]]]'
h...
Types
Arguments can optionally define a value type. Proc will attempt to coerce the given argument value into the defined
type. If the given value cannot be coerced into the defined argument type, an error will be returned. Available types
include: boolean
, integer
, number
, and string
.
something went wrong :(
Truncating a string to a coerced length
Setup
require "proc"
client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
truncate = client.type.string.truncate(
length: client.argument(:length, type: "integer")
) >> client.type.string.append(
value: "..."
)
truncate.call("hello", length: "3")
let truncate = client.type.string.truncate(
undefined, {length: client.argument("length", {type: "integer"})}
).compose(
client.type.string.append(
undefined, {value: "..."}
)
);
truncate.call("hello", {length: "3"});
curl "https://proc.run/core/exec?length=3" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "proc", ["{}", [">>", ["%%", "hello"]], ["$$", "length", ["%%", "3"]], ["()", "type.string.truncate", ["$$", "length", ["@@", "length", {"type": ["%%", "integer"]}]]], ["()", "type.string.append", ["$$", "value", ["%%", "..."]]]]]]'
hel...
Stuck? Want to chat about an idea? Join the community on Discord.