Acton
Acton standard libraryTlb

either

either.tolk standard library file

Represents a TL-B Either X Y: either X (left) or Y (right).

Alias semantics:

  • TlbEither<X, Y> is exactly TlbEitherLeft<X> | TlbEitherRight<Y>.

Encoding semantics:

  • Left branch starts with tag bit 0 (0b0).
  • Right branch starts with tag bit 1 (0b1).

Typical consumption pattern:

fun branchScore(choice: TlbEither<uint32, uint32>): int {
    return match (choice) {
        TlbEitherLeft => 1000 + choice.value,
        TlbEitherRight => 2000 + choice.value,
    };
}

Definitions

TlbEither

type TlbEither<X, Y> = TlbEitherLeft<X> | TlbEitherRight<Y>
Source code

TlbEither<X, Y>.left

@inline
fun TlbEither<X, Y>.left(value: X): TlbEitherLeft<X>

Left constructor. Encodes with tag bit 0 followed by value.

Source code

TlbEither<X, Y>.right

@inline
fun TlbEither<X, Y>.right(value: Y): TlbEitherRight<Y>

Right constructor. Encodes with tag bit 1 followed by value.

Source code

TlbEitherLeft

struct (0b0) TlbEitherLeft<X> {
    value: X
}

Left variant with explicit TLB tag 0b0.

Source code

TlbEitherRight

struct (0b1) TlbEitherRight<X> {
    value: X
}

Right variant with explicit TLB tag 0b1.

Source code

Last updated on

On this page