Types And Selections

Selecting A Day

This selection type is consumed by an exhaustive match.

Day is one of (
	monday
	tuesday
	wednesday
	thursday
	friday
	saturday
	sunday
)

fn isWeekend(day is Day) is bool (
	return day matches (
		Day.saturday
		Day.sunday true
		else false
	)
)

Explicit Selection Values

This example assigns protocol-style numeric values to named cases.

Status is one of (
	ok = 200
	created = 201
	badRequest = 400
	notFound = 404
)

fn isSuccess(status is Status) is bool (
	return status matches (
		Status.ok
		Status.created true
		else false
	)
)

A Generic Identity Function

Generic type parameters appear in the ordinary parameter list.

fn identity(T is type, value is T) is T (
	return value
)

fn retainName(name is string) is string (
	return identity(name)
)

Iterating A Selection Type

This example combines a selection declaration with type-level iteration.

Priority is one of (
	low = 1
	normal = 2
	high = 3
	urgent = 4
)

fn priorityNames() is string[] (
	names is editable string[]

	Priority each name value (
		names.push("((value)): ((name))")
	)

	return names
)