Transforms



Cue “functions”

You can use Cue definitions or structs to create function like objects. It is typical to have an input and output schema, and then you are free to do whatever else you like in between them.

function.cue

package function

import "strings"

// An input schema
#Input: {
	count: int
	msg: string
}

// An output schema
#Output: {
	val: string
}

#Transform: {
	// Input for the caller
	in: #Input
	// output for the caller
	out: #Output

	// intermediate fields
	_upper: strings.ToUpper(in.msg)
	_msg: strings.Join([_upper] * in.count, " ")

	// set output
	out: val: _msg
}

// Call transform
loudly: #Transform & { in: { msg: "ra", count: 3 } }

$ cue eval function.cue -e loudly
in: {
    count: 3
    msg:   "ra"
}
out: {
    val: "RA RA RA"
}

2021 Hofstadter, Inc