Skip to main content

Function - Procedure

Function.Procedure

A Procedure to build modular logic in Elara.

A procedure is a routine (or function) that can be called from within a

FunctionBuilder or ProcessBuilder. It is useful for factoring your code and repeating repetition.

Methods on the Procedure enable you to directly transform data from any number of named input parameters and return a single computed value. The body of the function works similarly to most imperative languages (like JavaScript/TypeScript) allowing for definition of temporary variables (with let), reassignment of defined variables (with assign), branching (with if, ifNull and match), loops (with while, forArray, forSet, forDict), as well as logging and raising errors (with log, warn and error). Inside any of these statements you can use East Expressions to access and manipulate data in scope.

Example

 // create a procedure to multiply two numbers
const my_procedure = new Procedure("my_procedure")
.input("x", FloatType)
.input("y", FloatType)
.output(FloatType)
.body(b => b
.return(vars => Multiply(vars.x, vars.y))
);

// create the predict_amount function
const x = new SourceBuilder("x").value({ value: 3.14 });
const y = new SourceBuilder("y").value({ value: 42.0 });

const f = new FunctionBuilder("f")
.input("x", x.outputStream())
.input("y", y.outputStream())
.procedure(my_procedure)
.body(block => block
.let("output", (vars, procs) => procs.my_procedure(Struct({ x: vars.x, y: vars.y })))
.return({ output: vars => vars.output })
);

Type parameters

NameType
Nameextends string
Inputsextends Record =

Procedure

constructor

new Procedure(name):

Procedure

Create a Procedure containing modular logic in Elara.

A procedure is a routine (or function) that can be called from within a

FunctionBuilder or ProcessBuilder. It is useful for factoring your code and repeating repetition.

Methods on the Procedure enable you to directly transform data from any number of named input parameters and return a single computed value. The body of the function works similarly to most imperative languages (like JavaScript/TypeScript) allowing for definition of temporary variables (with let), reassignment of defined variables (with assign), branching (with if, ifNull and match), loops (with while, forArray, forSet, forDict), as well as logging and raising errors (with log, warn and error). Inside any of these statements you can use East Expressions to access and manipulate data in scope.

Type parameters

NameType
Nameextends string
Inputsextends Record =

Parameters

NameType
nameName

Returns

Procedure

Example

 // create a procedure to multiply two numbers
const my_procedure = new Procedure("my_procedure")
.input("x", FloatType)
.input("y", FloatType)
.output(FloatType)
.body(b => b
.return(vars => Multiply(vars.x, vars.y))
);

// create the predict_amount function
const x = new SourceBuilder("x").value({ value: 3.14 });
const y = new SourceBuilder("y").value({ value: 42.0 });

const f = new FunctionBuilder("f")
.input("x", x.outputStream())
.input("y", y.outputStream())
.procedure(my_procedure)
.body(block => block
.let("output", (vars, procs) => procs.my_procedure(Struct({ x: vars.x, y: vars.y })))
.return({ output: vars => vars.output })
);

input

input(name, type):

Procedure<Name, Inputs & { [K in string]: T }>

Define an input parameter to a

Procedure.

Type parameters

NameType
InputNameextends string
Textends EastType

Parameters

NameTypeDescription
nameInputNamethe name of the input parameter
typeTthe EastType of the input parameter

Returns

Procedure<Name, Inputs & { [K in string]: T }>

Example

 // create a procedure to multiply two numbers
const my_procedure = new Procedure("my_procedure")
.input("x", FloatType)
.input("y", FloatType)
.output(FloatType)
.body(b => b
.return(vars => Multiply(vars.x, vars.y))
);

output

output(type): ProcedureBodyFinalizer

Define the type of the output of a

Procedure.

Type parameters

NameType
Textends EastType

Parameters

NameTypeDescription
typeTthe EastType of the output value

Returns

ProcedureBodyFinalizer

Example

 // create a procedure to multiply two numbers
const my_procedure = new Procedure("my_procedure")
.input("x", FloatType)
.input("y", FloatType)
.output(FloatType)
.body(b => b
.return(vars => Multiply(vars.x, vars.y))
);