Skip to content

Variables and Functions

Compare
Choose a tag to compare
@0xLeif 0xLeif released this 29 Sep 14:24
· 18 commits to main since this release

Variables

case void
case bool(Bool)
case int(Int)
case float(Float)
case double(Double)
case string(String)
case set(Set<Variable>)
case array([Variable])
case dictionary([Variable: Variable])

Variable Example

let text: Variable = .string("Hello, World!")
let list: Variable = .array(
	[
		.bool(false),
		.string("False"),
		.int(27)
	]
)

// ...

if case .string(let value) = text {
	print("String: \(value)")
}

if case .array(let value) = list,
   let lastValue = value.last,
   case .int(let number) = lastValue {
	print(number * 99)
}

Functions

case void(() -> ())
case `in`((Variable) -> ())
case out(() -> Variable)
case `inout`((Variable) -> Variable)

Function Example

let printString = Function.in { stringValue in
	guard case .string(let value) = stringValue else {
		return
	}

	print(value)
}
// ...
printString(.string("Hello, World..."))