Logical Procs, Argument Setters, Value Builders, and UUIDs

May 10, 2021

All new features to expand what's possible in your composed procs.

Logical Procs

Several new procs are introduced for controlling flow through composed procs, including: core.if, core.else, core.unless, and core.when.

Use these new procs to add logical branches to your compositions, supporting more complex workflows. Here's a simple example using core.if and core.else:

core.if(type.number.even) {
  core.echo("even")
} >> core.else {
  core.echo("odd")
}

The composition returns "even" when given an even number, and "odd" otherwise.

Dynamic Arguments

Arguments can now be defined at runtime using core.set. The argument value can be a static value or the result of a partial composition—both resolve to a referenceable value.

Set an argument when you want to refer to a value multiple times in a composed proc. Here's an example that stores a number under a random key in the key-value store:

core.set(
  name: "random_key",
  value: rand.string
)

keyv.set(
  :random_key,
  bucket: "values",
  value: rand.number
)

core.echo(:random_key)

The random key is returned, referenced through the :random_key token.

Value Builders

Certain Procs accept a specific value type as input. It's now possible to build initial values for every built-in type. Builders are available for the following types:

Builders can be called through the respective {type}.build proc, or implicitly through {type}. For example, calling type.string.build and type.string are equivalent.

UUIDs

The new uuid package lets you build and validate RFC 4122 UUIDs, or universally unique identifiers. You can read more about UUIDs and their many uses on Wikipedia.

Other Improvements

  • Base conversion. Adds a new base package for encoding and decoding to and from various bases (limited to Base64 support, but will be expanded over time).

  • More random procs. Three new procs landed in the rand package for generating random values: rand.bytes, rand.hex, and rand.string.

  • Date/Time parsing. Use time.parse to parse date/time strings into a time object.

  • Getting array values. Use type.array.value to get an array value at an index.

  • Splitting strings. Use type.string.split to split a string on a separator.