gleamgen/expression/block
Types
Blocks are used to group expressions together and are needed to define local variables.
{
use x <- block.with_let_declaration("x", expression.int(4))
use y <- block.with_let_declaration(
"y",
expression.math_operator(x, expression.Add, expression.int(5)),
)
block.ending_block(y)
}
|> block.build()
// type of Expression(Int)
|> expression.render(render.default_context())
This will generate the following code:
{
let x = 4
let y = x + 5
y
}
Blocks also can be created without the use syntax through new
and new_unchecked
pub opaque type BlockBuilder(type_)
pub type UseFunction(callback_args, ret) {
UseFunction(
function: Expression(types.Unchecked),
args: List(Expression(types.Unchecked)),
)
}
Constructors
-
UseFunction( function: Expression(types.Unchecked), args: List(Expression(types.Unchecked)), )
Functions
pub fn ending_block(expr: Expression(a)) -> BlockBuilder(a)
Used as the final expression in a block. If you want a dynamic final expression see ending_unchecked
.
This will set the type of the block to the type of the expression passed in.
pub fn ending_unchecked(
statements: List(Statement),
) -> BlockBuilder(a)
pub fn new_unchecked(
statements: List(Statement),
) -> Expression(a)
pub fn use_function1(
func: Expression(fn(a, b) -> c),
arg1: Expression(a),
) -> UseFunction(b, c)
pub fn use_function2(
func: Expression(fn(a, b, c) -> d),
arg1: Expression(a),
arg2: Expression(b),
) -> UseFunction(c, d)
pub fn use_function3(
func: Expression(fn(a, b, c, d) -> e),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
) -> UseFunction(d, e)
pub fn use_function4(
func: Expression(fn(a, b, c, d, e) -> f),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
) -> UseFunction(e, f)
pub fn use_function5(
func: Expression(fn(a, b, c, d, e, f) -> g),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
arg5: Expression(e),
) -> UseFunction(f, g)
pub fn use_function6(
func: Expression(fn(a, b, c, d, e, f, g) -> h),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
arg5: Expression(e),
arg6: Expression(f),
) -> UseFunction(g, h)
pub fn use_function7(
func: Expression(fn(a, b, c, d, e, f, g, h) -> i),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
arg5: Expression(e),
arg6: Expression(f),
arg7: Expression(g),
) -> UseFunction(h, i)
pub fn use_function8(
func: Expression(fn(a, b, c, d, e, f, g, h, i) -> j),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
arg5: Expression(e),
arg6: Expression(f),
arg7: Expression(g),
arg8: Expression(h),
) -> UseFunction(i, j)
pub fn use_function9(
func: Expression(fn(a, b, c, d, e, f, g, h, i, j) -> k),
arg1: Expression(a),
arg2: Expression(b),
arg3: Expression(c),
arg4: Expression(d),
arg5: Expression(e),
arg6: Expression(f),
arg7: Expression(g),
arg8: Expression(h),
arg9: Expression(i),
) -> UseFunction(j, k)
pub fn use_function_unchecked(
func: Expression(a),
args: List(Expression(Unchecked)),
) -> UseFunction(b, c)
pub fn with_expression(
expression: Expression(a),
handler: fn() -> BlockBuilder(b),
) -> BlockBuilder(b)
pub fn with_let_declaration(
variable: String,
value: Expression(a),
handler: fn(Expression(a)) -> BlockBuilder(b),
) -> BlockBuilder(b)
pub fn with_statements_unchecked(
statements: List(Statement),
handler: fn() -> BlockBuilder(a),
) -> BlockBuilder(a)
pub fn with_use0(
use_function: UseFunction(fn() -> a, a),
callback: fn() -> BlockBuilder(a),
) -> BlockBuilder(a)
pub fn with_use1(
use_function: UseFunction(fn(a) -> b, b),
arg1: String,
callback: fn(Expression(a)) -> BlockBuilder(b),
) -> BlockBuilder(b)
pub fn with_use2(
use_function: UseFunction(fn(a, b) -> c, c),
arg1: String,
arg2: String,
callback: fn(Expression(a), Expression(b)) -> BlockBuilder(c),
) -> BlockBuilder(c)
pub fn with_use3(
use_function: UseFunction(fn(a, b, c) -> d, d),
arg1: String,
arg2: String,
arg3: String,
callback: fn(Expression(a), Expression(b), Expression(c)) ->
BlockBuilder(d),
) -> BlockBuilder(d)
pub fn with_use4(
use_function: UseFunction(fn(a, b, c, d) -> e, e),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
) -> BlockBuilder(e),
) -> BlockBuilder(e)
pub fn with_use5(
use_function: UseFunction(fn(a, b, c, d, e) -> f, f),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
arg5: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
Expression(e),
) -> BlockBuilder(f),
) -> BlockBuilder(f)
pub fn with_use6(
use_function: UseFunction(fn(a, b, c, d, e, f) -> g, g),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
arg5: String,
arg6: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
Expression(e),
Expression(f),
) -> BlockBuilder(g),
) -> BlockBuilder(g)
pub fn with_use7(
use_function: UseFunction(fn(a, b, c, d, e, f, g) -> h, h),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
arg5: String,
arg6: String,
arg7: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
Expression(e),
Expression(f),
Expression(g),
) -> BlockBuilder(h),
) -> BlockBuilder(h)
pub fn with_use8(
use_function: UseFunction(fn(a, b, c, d, e, f, g, h) -> i, i),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
arg5: String,
arg6: String,
arg7: String,
arg8: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
Expression(e),
Expression(f),
Expression(g),
Expression(h),
) -> BlockBuilder(i),
) -> BlockBuilder(i)
pub fn with_use9(
use_function: UseFunction(fn(a, b, c, d, e, f, g, h, i) -> j, j),
arg1: String,
arg2: String,
arg3: String,
arg4: String,
arg5: String,
arg6: String,
arg7: String,
arg8: String,
arg9: String,
callback: fn(
Expression(a),
Expression(b),
Expression(c),
Expression(d),
Expression(e),
Expression(f),
Expression(g),
Expression(h),
Expression(i),
) -> BlockBuilder(j),
) -> BlockBuilder(j)
pub fn with_use_unchecked(
use_function: UseFunction(a, b),
args: List(String),
callback: fn(List(Expression(Unchecked))) -> BlockBuilder(b),
) -> BlockBuilder(b)