Sign in

    shared-lib

    [WIP] Personal Utils

    utility
    Download zip
    Author
    Version
    0.1.7
    License
    MIT
    Last updated
    last year
    Downloads
    49

    #[WIP] Personal Utils

    Indexable

    typealias Sequence[R, Int, A] as Indexable[R, A]

    Predicate

    typealias Reader[A, Bool] as Predicate[A]

    RandomRNG

    typealias State[UInt64, A] as RandomRNG[A]

    Refinement

    typealias Reader[A, B?] as Refinement[A, B]

    Alt

    pub(open) trait Alt {
    lor(Self, Self) -> Self
    alt(Self, Self) -> Self = _
    alt_with(Self, Lazy[Self]) -> Self = _
    alt_many(Self, Many[Self]) -> Self = _
    alt_array(Self, Array[Self]) -> Self = _
    }

    impl Alt for Option[A]

    ConcatToString

    pub(open) trait ConcatToString : ToString {
    concat_to_string(Self, Self) -> String
    }

    Debug

    pub(open) trait Debug : Show {
    to_debug_string(Self) -> String = _
    }

    impl Debug for String

    FromInt

    pub(open) trait FromInt {
    from_int(Int) -> Self
    }

    impl FromInt for Int

    FromString

    pub(open) trait FromString {
    from_string(String) -> Self
    }

    GetChar

    pub(open) trait GetChar {
    op_get(Self, Int) -> Char
    }

    impl GetChar for String

    GetUtf16CodePoint

    pub(open) trait GetUtf16CodePoint : GetChar + Length {
    get_utf16(Self, Int) -> Utf16CodePoint = _
    get_utf16_exn(Self, Int) -> Utf16CodePoint raise GetUtf16CharError = _
    }

    JoinToString

    pub(open) trait JoinToString {
    join_all(Self) -> String
    }

    impl JoinToString for Array[T]
    impl JoinToString for Iter[T]

    Length

    pub(open) trait Length {
    length(Self) -> Int
    is_empty(Self) -> Bool = _
    }

    impl Length for String
    impl Length for Option[V]
    impl Length for FixedArray[A]
    impl Length for Bytes
    impl Length for Array[A]
    impl Length for Map[K, V]

    Monoid

    pub(open) trait Monoid : Default + Semigroup {
    }

    NumType

    pub(open) trait NumType : UnsignedNum + Sub + Neg {
    }

    Order

    pub(open) trait Order : Compare {
    order(Self, Self) -> Ordering = _
    }

    Ring

    pub(open) trait Ring : Semiring {
    op_sub(Self, Self) -> Self
    op_neg(Self) -> Self
    }

    impl Ring for Int

    Semigroup

    pub(open) trait Semigroup {
    op_add(Self, Self) -> Self
    concat(Self, Self) -> Self = _
    concat_option(Self, Self?) -> Self = _
    concat_to_option(Self?, Self) -> Self? = _
    concat_many(Self, Many[Self]) -> Self = _
    concat_array(Self, Array[Self]) -> Self = _
    concat_iter(Self, Iter[Self]) -> Self = _
    }

    impl Semigroup for Unit
    impl Semigroup for Int
    impl Semigroup for UInt
    impl Semigroup for String
    impl Semigroup for Option[A]
    impl Semigroup for Array[A]

    Semiring

    pub(open) trait Semiring {
    zero() -> Self
    one() -> Self
    op_add(Self, Self) -> Self
    op_mul(Self, Self) -> Self
    }

    impl Semiring for Bool
    impl Semiring for Byte
    impl Semiring for Int

    Slice

    pub(open) trait Slice : Length {
    op_as_view(Self, start~ : Int, end~ : Int) -> Self
    }

    impl Slice for String
    impl Slice for FixedArray[Z]
    impl Slice for Array[Z]

    ToByte

    pub(open) trait ToByte {
    to_byte(Self) -> Byte
    }

    impl ToByte for Int

    ToChar

    pub(open) trait ToChar {
    to_char(Self) -> Char
    }

    impl ToChar for Char
    impl ToChar for Int

    ToInt

    pub(open) trait ToInt {
    to_int(Self) -> Int
    }

    impl ToInt for Int

    ToString

    pub(open) trait ToString {
    to_string(Self) -> String
    }

    impl ToString for Char
    impl ToString for String

    UnsignedNum

    pub(open) trait UnsignedNum : FromInt + ToInt + ToByte + Add + Mul + Zero {
    one() -> Self = _
    }

    WriteToBuffer

    pub(open) trait WriteToBuffer : Show {
    write_to(Self,
    T
    ) -> Unit
    }

    WriteToStringBuilder

    pub(open) trait WriteToStringBuilder : Show {
    write_to(Self, StringBuilder) -> Unit
    }

    Zero

    pub(open) trait Zero {
    zero() -> Self
    }

    impl Zero for Int
    impl Zero for Int16
    impl Zero for Int64
    impl Zero for UInt
    impl Zero for UInt16
    impl Zero for UInt64
    impl Zero for Float
    impl Zero for Double

    Apply

    #external
    pub(all) type Apply

    Apply::ap

    fn[A, B] Apply::ap(self : Reader[A, B], a : A) -> B

    Cursor

    pub(all) type Cursor Int

    impl Compare for Cursor
    impl Default for Cursor
    impl Eq for Cursor
    impl Hash for Cursor
    impl Show for Cursor
    impl ToJson for Cursor
    impl ToInt for Cursor

    Cursor::inner

    fn Cursor::inner(self : Cursor) -> Int
    Convert newtype to its underlying type, automatically derived.

    Cursor::op_add

    fn Cursor::op_add(a : Cursor, b : Cursor) -> Cursor

    DebugFn

    pub(all) type DebugFn[A] () -> A

    impl Show for DebugFn[A]

    DebugFn::inner

    fn[A] DebugFn::inner(self : DebugFn[A]) -> (() -> A)
    Convert newtype to its underlying type, automatically derived.

    Either

    pub(all) enum Either[L, R] {
    Left(L)
    Right(R)
    }

    impl Show for Either[L, R]

    Either::from_option

    fn[A, B] Either::from_option(option : A?, or : B) -> Either[B, A]

    Either::is_left

    fn[A, B] Either::is_left(self : Either[A, B]) -> Bool

    Either::is_right

    fn[A, B] Either::is_right(self : Either[A, B]) -> Bool

    Either::unwrap_left

    fn[A, B] Either::unwrap_left(self : Either[A, B]) -> A

    Either::unwrap_right

    fn[A, B] Either::unwrap_right(self : Either[A, B]) -> B

    Endianness

    pub(all) enum Endianness {
    LittleEndian
    BigEndian
    NetworkEndian
    }
    Byte order, aka "endianness".

    • LittleEndian: Little-endian.
    • BigEndian: Big-endian.
    • NetworkEndian: Network byte order defined by IETF RFC 1700.

    note:
    • Little-endian is the de-facto standard practice for current computer architectures, and the standardized byte order of WASM.
    • NativeEndian (system native-endian) may be introduced in the future.
    impl Eq for Endianness
    impl Show for Endianness

    Foldable

    pub(all) type Foldable[R, A, B] (R, B, (B, A) -> B) -> B

    Foldable::array

    fn[A, B] Foldable::array() -> Foldable[Array[A], A, B]

    Foldable::fixed_array

    fn[A, B] Foldable::fixed_array() -> Foldable[FixedArray[A], A, B]

    Foldable::inner

    fn[R, A, B] Foldable::inner(self : Foldable[R, A, B]) -> ((R, B, (B, A) -> B) -> B)
    Convert newtype to its underlying type, automatically derived.

    Foldable::many

    fn[A, B] Foldable::many() -> Foldable[Many[A], A, B]

    FoldableWithIndex

    pub(all) type FoldableWithIndex[R, A, B] (R, B, (Int, B, A) -> B) -> B

    FoldableWithIndex::array

    fn[A, B] FoldableWithIndex::array() -> FoldableWithIndex[Array[A], A, B]

    FoldableWithIndex::fixed_array

    fn[A, B] FoldableWithIndex::fixed_array() -> FoldableWithIndex[FixedArray[A], A, B]

    FoldableWithIndex::inner

    fn[R, A, B] FoldableWithIndex::inner(self : FoldableWithIndex[R, A, B]) -> ((R, B, (Int, B, A) -> B) -> B)
    Convert newtype to its underlying type, automatically derived.

    FoldableWithIndex::many

    fn[A, B] FoldableWithIndex::many() -> FoldableWithIndex[Many[A], A, B]

    GetUtf16CharError

    pub(all) enum GetUtf16CharError {
    OutOfRange(Int, Int)
    InvalidStringHighSurrogate
    InvalidStringLowSurrogate
    UnreachableCode(Int)
    }

    IReader

    #external
    pub(all) type IReader

    IReader::chain

    fn[R, A, B] IReader::chain(ab : (R) -> A, bc : (A) -> ((R) -> B)) -> ((R) -> B)

    IReader::map

    fn[R, A, B] IReader::map(ab : (R) -> A, bc : (A) -> B) -> ((R) -> B)

    Identity

    #external
    pub type Identity

    Identity::ap

    fn[A, B] Identity::ap(ab : (A) -> B, a : A) -> B

    Identity::ap_exn

    fn[A, B, E : Error] Identity::ap_exn(ab : (A) -> B raise E, a : A) -> B raise E

    Identity::map

    fn[A, B] Identity::map(a : A, f : (A) -> B) -> B

    Identity::tap

    fn[A, B] Identity::tap(a : A, f : (A) -> B) -> A

    Lazy

    pub(all) type Lazy[A] () -> A

    impl Default for Lazy[A]
    impl Semigroup for Lazy[A]

    Lazy::ap

    fn[A, B] Lazy::ap(lazy_ab : Lazy[(A) -> B], lazy_a : Lazy[A]) -> Lazy[B]

    Lazy::ap1

    fn[A, A1, B] Lazy::ap1(lazy_ab : Lazy[(A, A1) -> B], lazy_a : Lazy[A], lazy_a1 : Lazy[A1]) -> Lazy[B]

    Lazy::chain

    fn[A, T2] Lazy::chain(lazy_ : Lazy[A], f : (A) -> Lazy[T2]) -> Lazy[T2]

    Lazy::get

    fn[A] Lazy::get(lazy_ : Lazy[A]) -> A

    Lazy::if_memo

    fn[A] Lazy::if_memo(lazy_ : Lazy[A], cond : Bool) -> Lazy[A]

    Lazy::inner

    fn[A] Lazy::inner(self : Lazy[A]) -> (() -> A)
    Convert newtype to its underlying type, automatically derived.

    Lazy::map

    fn[A, T2] Lazy::map(lazy_ : Lazy[A], f : (A) -> T2) -> Lazy[T2]

    Lazy::memo

    fn[A] Lazy::memo(lazy_ : Lazy[A]) -> Lazy[A]

    Lazy::of

    fn[A] Lazy::of(lazy_ : A) -> Lazy[A]

    Lazy::sequence_array

    fn[A] Lazy::sequence_array(lazy_ : Array[Lazy[A]]) -> Lazy[Array[A]]

    Lazy::sequence_many

    fn[A] Lazy::sequence_many(lazy_ : Many[Lazy[A]]) -> Lazy[Many[A]]

    Lazy::string_builder

    fn Lazy::string_builder() -> StringBuilder

    Lazy::to_reader

    fn[R, A] Lazy::to_reader(lazy_ : Lazy[A]) -> Reader[R, A]

    Many

    pub(all) type Many[A] FixedArray[A]

    impl Default for Many[A]
    impl Show for Many[A]
    impl JoinToString for Many[T]
    impl Length for Many[A]
    impl Slice for Many[A]

    Many::contains

    fn[A : Eq] Many::contains(self : Many[A], val : A) -> Bool

    Many::contains_ref

    fn[A] Many::contains_ref(self : Many[A], val : A) -> Bool

    Many::fold

    fn[A, B] Many::fold(self : Many[A], init~ : B, f : (B, A) -> B) -> B

    Many::foldi

    fn[A, B] Many::foldi(self : Many[A], init~ : B, f : (Int, B, A) -> B) -> B

    Many::from_array

    fn[A] Many::from_array(array : Array[A]) -> Many[A]

    Many::inner

    fn[A] Many::inner(self : Many[A]) -> FixedArray[A]
    Convert newtype to its underlying type, automatically derived.

    Many::iter

    fn[A] Many::iter(self : Many[A]) -> Iter[A]

    Many::make

    fn[A] Many::make(len : Int, init : A) -> Many[A]

    Many::not_contains

    fn[A : Eq] Many::not_contains(self : Many[A], val : A) -> Bool

    Many::not_contains_ref

    fn[A] Many::not_contains_ref(self : Many[A], val : A) -> Bool

    Many::op_as_view

    fn[A] Many::op_as_view(self : Many[A], start~ : Int, end? : Int) -> Many[A]

    Many::op_get

    fn[A] Many::op_get(self : Many[A], i : Int) -> A

    Many::op_set

    fn[A] Many::op_set(self : Many[A], i : Int, v : A) -> Unit

    Many::to_array

    fn[A] Many::to_array(self : Many[A]) -> Array[A]

    Many::to_fixed_array

    fn[A] Many::to_fixed_array(self : Many[A]) -> FixedArray[A]

    Many::to_show

    fn[I : Show] Many::to_show(self : Many[I]) -> Many[Show]

    Many::to_show_array

    fn[I : Show] Many::to_show_array(self : Many[I]) -> Array[Show]

    MonoidPattern

    pub(all) type MonoidPattern[A] (T_Monoid[A], A)

    MonoidPattern::inner

    fn[A] MonoidPattern::inner(self : MonoidPattern[A]) -> (T_Monoid[A], A)
    Convert newtype to its underlying type, automatically derived.

    NonEmptyString

    pub type NonEmptyString String

    NonEmptyString::inner

    fn NonEmptyString::inner(self : NonEmptyString) -> String
    Convert newtype to its underlying type, automatically derived.

    NonEmptyString::of

    fn NonEmptyString::of(str : String) -> NonEmptyString

    Ordering

    pub(all) enum Ordering {
    Less
    Greater
    Eq
    }

    impl Eq for Ordering
    impl Show for Ordering

    Ordering::int_to_ordering

    fn Ordering::int_to_ordering(i : Int) -> Ordering

    Prediate

    pub(all) type Prediate[A] ((A) -> Bool, Show)

    impl Show for Prediate[A]
    impl Alt for Prediate[A]

    Prediate::inner

    fn[A] Prediate::inner(self : Prediate[A]) -> ((A) -> Bool, Show)
    Convert newtype to its underlying type, automatically derived.

    Prediate::land

    fn[A] Prediate::land(self : Prediate[A], orw : Prediate[A]) -> Prediate[A]

    Prediate::op_get

    fn[A] Prediate::op_get(self : Prediate[A], arg : A) -> Bool

    Prediate::op_neg

    fn[A] Prediate::op_neg(self : Prediate[A]) -> Prediate[A]

    Prediate::to_string

    fn[A] Prediate::to_string(self : Prediate[A]) -> String

    Reader

    pub(all) type Reader[R, A] (R) -> A

    impl Default for Reader[R, A]
    impl Semigroup for Reader[R, A]

    Reader::_traverse_arrayi

    fn[R, A, B] Reader::_traverse_arrayi(arr : Array[A], f : (Int, A) -> Reader[R, B]) -> Reader[R, Array[B]]

    Reader::ap

    fn[R, A, B] Reader::ap(fab : Reader[R, (A) -> B], fa : Reader[R, A]) -> Reader[R, B]

    Reader::ap_first

    fn[R, A, B] Reader::ap_first(fa : Reader[R, A], fb : Reader[R, B]) -> Reader[R, A]

    Reader::ap_second

    fn[R, A, B] Reader::ap_second(fa : Reader[R, A], fb : Reader[R, B]) -> Reader[R, B]

    Reader::ap_tuple

    fn[R, A, B] Reader::ap_tuple(fa : Reader[R, A], fb : Reader[R, B]) -> Reader[R, (A, B)]

    Reader::ap_tuple_rev

    fn[R, A, B] Reader::ap_tuple_rev(fa : Reader[R, A], fb : Reader[R, B]) -> Reader[R, (B, A)]

    Reader::ask

    fn[R] Reader::ask() -> Reader[R, R]

    Reader::ask_reader

    fn[R, A] Reader::ask_reader(f : (R) -> Reader[R, A]) -> Reader[R, A]

    Reader::asks

    fn[R, A] Reader::asks(f : (R) -> A) -> Reader[R, A]

    Reader::bind_json

    fn[R, A : ToJson] Reader::bind_json(self : Reader[R, Json], key : String, fa : Reader[R, A]) -> Reader[R, Json]

    Reader::bind_map

    fn[R, K : Hash + Eq, A] Reader::bind_map(self : Reader[R, Map[K, A]], key : K, fa : Reader[R, A]) -> Reader[R, Map[K, A]]

    Reader::bind_to_json

    fn[R, A : ToJson] Reader::bind_to_json(self : Reader[R, A], key : String) -> Reader[R, Json]

    Reader::bind_to_map

    fn[R, K : Hash + Eq, A] Reader::bind_to_map(self : Reader[R, A], key : K) -> Reader[R, Map[K, A]]

    Reader::chain

    fn[R, A, B] Reader::chain(self : Reader[R, A], f : (A) -> Reader[R, B]) -> Reader[R, B]

    Reader::chain_first

    fn[R, A, B] Reader::chain_first(self : Reader[R, A], f : (A) -> Reader[R, B]) -> Reader[R, A]

    Reader::compose

    fn[A, B, C] Reader::compose(ab : Reader[A, B], bc : Reader[B, C]) -> Reader[A, C]

    Reader::flatten

    fn[R, A] Reader::flatten(self : Reader[R, Reader[R, A]]) -> Reader[R, A]

    Reader::from_lazy

    fn[R, A] Reader::from_lazy(lazy_ : Lazy[A]) -> Reader[R, A]

    Reader::inner

    fn[R, A] Reader::inner(self : Reader[R, A]) -> ((R) -> A)
    Convert newtype to its underlying type, automatically derived.

    Reader::locally

    fn[R, A, R2] Reader::locally(self : Reader[R, A], f : (R2) -> R) -> Reader[R2, A]

    Reader::map

    fn[R, A, B] Reader::map(self : Reader[R, A], f : (A) -> B) -> Reader[R, B]

    Reader::map_trace

    fn[R, A, B] Reader::map_trace(self : Reader[R, A], f : (A, R) -> B) -> Reader[R, B]

    Reader::memo

    fn[K : Hash + Eq, V] Reader::memo(f : Reader[K, V]) -> Reader[K, V]

    Reader::memo_ignore_arg

    fn[K, V] Reader::memo_ignore_arg(f : Reader[K, V]) -> Reader[K, V]

    Creates a memoized version of a reader that caches the first result and returns it for all subsequent calls, regardless of the input value.

    Parameters:

    • reader : A reader function of type Reader[K, V] that takes an input of type K and produces an output of type V.

    Returns a new reader that will compute the value only once on its first call and return the cached value for all subsequent calls.

    Example:

    test "Reader::memo_ignore_arg" {
    let counter = StringBuilder::new()
    let reader = Reader(fn(x : Int) {
    counter.write_string("computed\n")
    42
    })
    let memoized = Reader::memo_ignore_arg(reader)
    inspect!(memoized.read(1), content="42")
    inspect!(memoized.read(2), content="42")
    inspect!(counter.to_string(), content="computed\n")
    }

    Reader::not

    fn[A] Reader::not(pred : Reader[A, Bool]) -> Reader[A, Bool]

    Reader::of

    fn[R, A] Reader::of(a : A) -> Reader[R, A]

    Reader::promap

    fn[E, A, B, D] Reader::promap(fea : Reader[E, A], f : (D) -> E, g : (A) -> B) -> Reader[D, B]

    Reader::read

    fn[R, A] Reader::read(reader : Reader[R, A], arg : R) -> A

    Reader::read_curry

    fn[R, A] Reader::read_curry(arg : R) -> ((Reader[R, A]) -> A)

    Reader::sequence_array

    fn[R, A] Reader::sequence_array(arr : Array[Reader[R, A]]) -> Reader[R, Array[A]]

    Reader::sequence_fixed_array

    fn[R, A] Reader::sequence_fixed_array(arr : FixedArray[Reader[R, A]]) -> Reader[R, FixedArray[A]]

    Reader::sequence_many

    fn[R, A] Reader::sequence_many(arr : Many[Reader[R, A]]) -> Reader[R, Many[A]]

    Reader::sequence_map

    fn[R, K : Hash + Eq, A] Reader::sequence_map(map : Map[K, Reader[R, A]]) -> Reader[R, Map[K, A]]

    Reader::tap

    fn[R, A, B] Reader::tap(fa : Reader[R, A], f : (A) -> B) -> Reader[R, A]

    Reader::to_refinement

    fn[A] Reader::to_refinement(pred : Reader[A, Bool]) -> Reader[A, A?]

    Reader::to_refinement_rev

    fn[A] Reader::to_refinement_rev(pred : Reader[A, Bool]) -> Reader[A, A?]

    Reader::traverse_array

    fn[R, A, B] Reader::traverse_array(f : (A) -> Reader[R, B]) -> ((Array[A]) -> Reader[R, Array[B]])

    Reader::traverse_arrayi

    fn[R, A, B] Reader::traverse_arrayi(f : (Int, A) -> Reader[R, B]) -> ((Array[A]) -> Reader[R, Array[B]])

    Reader::traverse_non_empty_arrayi

    fn[R, A, B] Reader::traverse_non_empty_arrayi(f : (Int, A) -> Reader[R, B]) -> ((Array[A]) -> Reader[R, Array[B]])

    Reader::unwrap

    fn[A, B] Reader::unwrap(self : Reader[A, B]) -> ((A) -> B)

    ReaderT

    #external
    pub type ReaderT

    Sequence

    pub(all) struct Sequence[R, I, A] {
    make : (Int, A) -> R
    op_get : (R, I) -> A
    op_set : (R, I, A) -> Unit
    }

    Sequence::array

    fn[A] Sequence::array() -> Sequence[Array[A], Int, A]

    Sequence::default

    fn[R : Default, I, A] Sequence::default(_self : Sequence[R, I, A]) -> R

    Sequence::fixed_array

    fn[A] Sequence::fixed_array() -> Sequence[FixedArray[A], Int, A]

    Sequence::get

    fn[R, I, A] Sequence::get(self : Sequence[R, I, A], r : R, i : I) -> A

    Sequence::make

    fn[R, I, A] Sequence::make(self : Sequence[R, I, A], len : Int, init~ : A) -> R

    Sequence::many

    fn[A] Sequence::many() -> Sequence[Many[A], Int, A]

    Sequence::separated

    fn[RA : Length, RB : Default, RC : Default, A, B, C] Sequence::separated(self : Sequence[RA, Int, A], fb~ : Sequence[RB, Int, B], fc~ : Sequence[RC, Int, C], input : RA, f : (A) -> (B, C)) -> (RB, RC)

    Sequence::sequence_transform

    fn[T1 : Length, A, B, T2 : Default] Sequence::sequence_transform(self : Sequence[T1, Int, A], input : T1, f : (A) -> B, target~ : Sequence[T2, Int, B]) -> T2

    Sequence::set

    fn[R, I, A] Sequence::set(self : Sequence[R, I, A], r : R, i : I, a : A) -> Unit

    State

    pub(all) type State[S, A] (S) -> (A, S)

    State::evaluate

    fn[S, A] State::evaluate(self : State[S, A], state : S) -> A

    State::inner

    fn[S, A] State::inner(self : State[S, A]) -> ((S) -> (A, S))
    Convert newtype to its underlying type, automatically derived.

    State::map

    fn[S, A, B] State::map(state : State[S, A], f : (A) -> B) -> State[S, B]

    T_Monoid

    pub(all) struct T_Monoid[A] {
    empty : () -> A
    concat : (A, A) -> A
    }

    T_Semigroup

    pub(all) struct T_Semigroup[A] {
    concat : (A, A) -> A
    }

    Utf16CodePoint

    pub(all) enum Utf16CodePoint {
    BMP(Char)
    HighSurrogate(Char)
    LowSurrogate(Char)
    }
    The type of a word (16-bit) appears in a UTF-16 sequence:

    • BMP: Basic Multilingual Plane. (including 0x0000–0xD7FF and 0xE000–0xFFFF)
    • HighSurrogate: The first word of a surrogate pair. (including 0xD800–0xDBFF)
    • LowSurrogate: The second word of a surrogate pair. (including 0xDC00–0xDFFF)

    Utf16CodePoint::to_char

    fn Utf16CodePoint::to_char(self : Utf16CodePoint) -> Char

    Utf16CodePoint::to_len

    fn Utf16CodePoint::to_len(self : Utf16CodePoint) -> Int

    Utf16CodePoint::to_tuple

    fn Utf16CodePoint::to_tuple(self : Utf16CodePoint) -> (Char, Int)

    Monoid

    Monoid::concat

    fn[A : Monoid + Default + Semigroup] Monoid::concat(x : A, y : A) -> A

    Monoid::empty

    fn[A : Monoid + Default + Semigroup] Monoid::empty() -> A

    DEBUGGER

    let DEBUGGER : Bool

    VERSION

    let VERSION : String

    __unsafe_cast

    fn[A, B] __unsafe_cast(a : A) -> B

    __unsafe_cast_arrow

    fn[A, B, C, D] __unsafe_cast_arrow(a : (A) -> C) -> ((B) -> D)

    abort

    fn[T, A : Debug + Show] abort(msg : A, loc~ : SourceLoc = _) -> T

    abort_with

    fn[T, A : Debug + Show] abort_with(f : () -> A, loc~ : SourceLoc = _) -> T

    alt_all

    fn[A : Alt + Zero] alt_all(x : Many[A]) -> A

    alt_all_array

    fn[A : Alt + Zero] alt_all_array(x : Array[A]) -> A

    alts

    fn[A : Alt] alts(x : Many[A]) -> A

    alts_or

    fn[A : Alt] alts_or(x : Many[A], or_else : Lazy[A]) -> A

    arg_loc

    fn arg_loc(loc~ : ArgsLoc = _) -> ArgsLoc

    check_is

    fn[A] check_is(a : A, b : A) -> Bool

    combine_surrogate_pair_int

    fn combine_surrogate_pair_int(high : Int, low : Int) -> Char

    compose

    fn[A, B, C] compose(fa : (A) -> B, fb : (B) -> C) -> ((A) -> C)

    compose_2

    fn[A, B, C, D] compose_2(fa : (A) -> B, fb : (B) -> C, fc : (C) -> D) -> ((A) -> D)

    concat3

    fn[A : Semigroup] concat3(a : A, b : A, c : A) -> A

    concat_all

    fn[A : Monoid + Default + Semigroup] concat_all(x : Many[A]) -> A

    concat_all_array

    fn[A : Monoid + Default + Semigroup] concat_all_array(x : Array[A]) -> A

    concat_all_iter

    fn[A : Monoid + Default + Semigroup] concat_all_iter(x : Iter[A]) -> A

    const_empty_array

    fn[A, B] const_empty_array(_a : A) -> Array[B]

    const_empty_string

    fn[A] const_empty_string(_arg : A) -> String

    const_false

    fn[A] const_false(_a : A) -> Bool

    const_identity

    fn[N, A] const_identity(_n : N) -> ((A) -> A)

    const_one

    fn[A] const_one(_arg : A) -> Int

    const_true

    fn[A] const_true(_arg : A) -> Bool

    const_unit

    fn[A] const_unit(_ : A) -> Unit

    const_unit_0

    fn const_unit_0() -> Unit

    const_zero

    fn[A] const_zero(_arg : A) -> Int

    constant

    fn[N, A] constant(a : A) -> ((N) -> A)

    constant_0

    fn[A] constant_0(a : A) -> (() -> A)

    constant_0_from_lazy

    fn[A] constant_0_from_lazy(a : Lazy[A]) -> (() -> A)

    constant_2

    fn[N, N2, A] constant_2(a : A) -> ((N, N2) -> A)

    constant_as_show

    fn[I : Show] constant_as_show(a : I) -> Show

    constant_exn

    fn[R, A, E : Error] constant_exn(a : E) -> ((R) -> A raise E)

    constant_exn_0

    fn[A, E : Error] constant_exn_0(a : E) -> (() -> A raise E)

    constant_from_lazy

    fn[R, A] constant_from_lazy(a : Lazy[A]) -> ((R) -> A)

    constant_none

    fn[A] constant_none() -> A?

    curried_2

    fn[T, U, V, W] curried_2(f : (T, U, W) -> V, y : U, z : W) -> ((T) -> V)

    Curry a function.

    curried_add

    fn[A : Semigroup] curried_add(a : A) -> ((A) -> A)

    curried_add_pre

    fn[A : Semigroup] curried_add_pre(a : A) -> ((A) -> A)

    curried_apply

    fn[A, B] curried_apply(a : A) -> (((A) -> B) -> B)

    curried_apply_exn

    fn[A, B, E : Error] curried_apply_exn(a : A) -> (((A) -> B raise E) -> B raise E)

    curried_apply_rev

    fn[A, B] curried_apply_rev(a : (A) -> B) -> ((A) -> B)

    curried_concat

    fn[A : Semigroup] curried_concat(x : A, y : A) -> A

    curried_eq

    fn[A : Eq] curried_eq(a : A) -> ((A) -> Bool)

    curried_eq_not

    fn[A : Eq] curried_eq_not(a : A) -> ((A) -> Bool)

    curried_first

    fn[T, U, V] curried_first(f : (T, U) -> V, y : U) -> ((T) -> V)

    Curry a function.

    Example

    let add = fn(x : Int, y : String) -> String { x.to_string() + y } let curried_add = @lib.curried_first(add, "str") assert_eq!(curried_add(1), "1str")

    curried_is

    fn[A] curried_is(a : A) -> ((A) -> Bool)

    curried_is_not

    fn[A] curried_is_not(a : A) -> ((A) -> Bool)

    curried_maximum

    fn[A : Compare + Eq] curried_maximum(a : A) -> ((A) -> A)

    curried_minimum

    fn[A : Compare + Eq] curried_minimum(a : A) -> ((A) -> A)

    curried_not

    fn[T, U] curried_not(f : (T, U) -> Bool, x : T) -> ((U) -> Bool)

    curried_one_of

    fn[A : Eq] curried_one_of(a : Many[A]) -> ((A) -> Bool)

    curried_one_of_not

    fn[A : Eq] curried_one_of_not(a : Many[A]) -> ((A) -> Bool)

    curried_second

    fn[T, U, V] curried_second(f : (T, U) -> V, x : T) -> ((U) -> V)

    Curry a function.

    Example

    let add = fn(x : Int, y : String) -> String { x.to_string() + y } let curried_add = @lib.curried_second(add, 1) assert_eq!(curried_add("str"), "1str")

    curried_tuple_fst

    fn[A, B] curried_tuple_fst(a : A) -> ((B) -> (A, B))

    curried_tuple_map_fst

    fn[T, U, V] curried_tuple_map_fst(f : (T) -> U) -> (((T, V)) -> (U, V))

    curried_tuple_map_snd

    fn[T, U, V] curried_tuple_map_snd(f : (T) -> U) -> (((V, T)) -> (V, U))

    curried_tuple_snd

    fn[A, B] curried_tuple_snd(a : A) -> ((B) -> (B, A))

    curry_1

    fn[A, B, C] curry_1(f : (A, B) -> C) -> ((A) -> ((B) -> C))

    curry_2

    fn[A, B, C, D] curry_2(f : (A, B, C) -> D) -> ((A) -> ((B) -> ((C) -> D)))

    curry_2_first

    fn[A, B, C, D] curry_2_first(f : (A, B, C) -> D) -> ((A) -> ((B, C) -> D))

    curry_3

    fn[A, B, C, D, E] curry_3(f : (A, B, C, D) -> E) -> ((A) -> ((B) -> ((C) -> ((D) -> E))))

    curry_4

    fn[A, B, C, D, E, F] curry_4(f : (A, B, C, D, E) -> F) -> ((A) -> ((B) -> ((C) -> ((D) -> ((E) -> F)))))

    dev_println

    fn[T : Show] dev_println(input : T) -> Unit

    digit_char_2_int

    fn digit_char_2_int(char : Char) -> Int

    Converts a character representing a digit to its corresponding integer value.

    Parameters:

    • char : A character in the range '0' to '9'.

    Returns the integer value of the digit.

    Throws a panic error if the input character is not a valid digit.

    Example:

    test "digit_2_int" {
    inspect!(digit_2_int('5'), content="5")
    inspect!(digit_2_int('0'), content="0")
    }

    test "panic digit_2_int/invalid_char" {
    let _ = digit_2_int('a')

    }
    fn[A : Eq] eq(x : A, y : A) -> Bool

    get_utf16_char_at

    fn[T : GetUtf16CodePoint + GetChar + Length] get_utf16_char_at(input : T, idx_word : Int) -> Utf16CodePoint
    Get the char appeared at n-th word (16-bit) of input string.

    Examples

    Iterate a string including U+10000 by valid chars (unicode code point) using a while loop:

    let str = "\u{6708}\u{1f430}\u{5154}" // 月🐰兔
    let mut i = 0
    while i < str.length() {
    let (ch, ty) = get_utf16_char_at(str, i)
    println(ch)

    // advance by 2 words on a surrogate pair
    i += if ty != Utf16WordType::BMP { 1 } else { 2 }
    }

    Panics

    Panics if index out of range, or any invalid value (code point or surrogate pair) appears at specified position.

    hex_2_int

    fn hex_2_int(str : String) -> Int

    hex_2_int_compose

    fn hex_2_int_compose(int : Int, i : Int, char : Char) -> Int

    hex_2_int_compose_int

    fn hex_2_int_compose_int(int : Int, i : Int, int2 : Int) -> Int

    hex_char_2_int

    fn hex_char_2_int(char : Char) -> Int

    identity

    fn[A] identity(a : A) -> A

    ignore2

    fn[A, B] ignore2(_a : A, _b : B) -> Unit

    int_be_from_bytes

    fn int_be_from_bytes(bytes : FixedArray[Byte], offset : Int) -> Int
    Extract an Int from certain position of FixedArray[Byte] by big-endian.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_from_bytes

    fn int_from_bytes(bytes : FixedArray[Byte], offset : Int, endian : Endianness, source~ : SourceLoc = _) -> Int
    Extract an Int from certain position of FixedArray[Byte] by specified endianness.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_into_bytes

    fn int_into_bytes(v : Int, endian : Endianness, target : FixedArray[Byte], offset : Int) -> Unit
    Write bytes representation of an Int by specified endianness into target FixedArray[Byte] at certain offset.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_into_bytes_be

    fn int_into_bytes_be(v : Int, target : FixedArray[Byte], offset : Int) -> Unit
    Write bytes representation of an Int by big-endian into target FixedArray[Byte] at certain offset.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_into_bytes_le

    fn int_into_bytes_le(v : Int, target : FixedArray[Byte], offset : Int) -> Unit
    Write bytes representation of an Int by little-endian into target FixedArray[Byte] at certain offset.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_le_from_bytes

    fn int_le_from_bytes(bytes : FixedArray[Byte], offset : Int) -> Int
    Extract an Int from certain position of FixedArray[Byte] by little-endian.

    Panics

    4 bytes of data are required from offset position. Panics when insufficient.

    int_to_bytes

    fn int_to_bytes(v : Int, endian : Endianness) -> FixedArray[Byte]
    Get bytes representation of an Int by specified endianness.

    int_to_bytes_be

    fn int_to_bytes_be(v : Int) -> FixedArray[Byte]
    Get bytes representation of an Int by big-endian.

    int_to_bytes_le

    fn int_to_bytes_le(v : Int) -> FixedArray[Byte]
    Get bytes representation of an Int by little-endian.

    is_empty

    fn[T : Length] is_empty(target : T) -> Bool

    is_identity

    fn[A, B] is_identity(a : (A) -> B) -> Bool

    is_not

    fn[A] is_not(a : A, b : A) -> Bool

    is_not_empty

    fn[T : Length] is_not_empty(target : T) -> Bool

    iter_append

    fn[T] iter_append(iter : Iter[T], a : T) -> Iter[T]

    join

    fn[A : WriteToStringBuilder + Show, B : WriteToStringBuilder + Show] join(a : A, b : B) -> String

    join3

    fn[A : WriteToStringBuilder + Show, B : WriteToStringBuilder + Show, C : WriteToStringBuilder + Show] join3(a : A, b : B, c : C) -> String

    join_all

    fn[T : JoinToString] join_all(all : T) -> String

    join_array

    fn join_array(all : Array[WriteToStringBuilder]) -> String

    join_fixed_array

    fn join_fixed_array(all : FixedArray[WriteToStringBuilder]) -> String

    join_iter

    fn join_iter(all : Iter[WriteToStringBuilder]) -> String

    join_many

    fn join_many(all : Many[WriteToStringBuilder]) -> String

    lazy_invoke

    fn[A, B] lazy_invoke(f : (A) -> B, arg : A) -> Lazy[B]

    lift_arg

    fn[R, A] lift_arg(f : () -> A) -> ((R) -> A)

    lift_arg_0_2

    fn[R, R2, A] lift_arg_0_2(f : () -> A) -> ((R, R2) -> A)

    lift_arg_2

    fn[R, R2, A] lift_arg_2(f : (R) -> A) -> ((R, R2) -> A)

    lift_exn

    fn[R, A, E : Error] lift_exn(f : (R) -> A) -> ((R) -> A raise E)

    lift_exn_0

    fn[A, E : Error] lift_exn_0(f : () -> A) -> (() -> A raise E)

    map_fst

    fn[T, U, V] map_fst(f : (T) -> U, tuple : (T, V)) -> (U, V)

    Map a function over the first element of a tuple.

    Example

    test "Tuple::map_fst" { let tuple = (1, 2) let mapped = @tuple.map_fst(fn(x : Int) -> Int { x + 1 }, tuple) assert_eq(mapped, (2, 2)) }

    map_snd

    fn[T, U, V] map_snd(f : (T) -> U, tuple : (V, T)) -> (V, U)

    Map a function over the second element of a tuple.

    Example

    test "Tuple::map_snd" { let tuple = (1, 2) let mapped = @tuple.map_snd(fn(x : Int) -> Int { x + 1 }, tuple) assert_eq(mapped, (1, 3)) }

    memorized

    fn[K : Hash + Eq, V] memorized(f : (K) -> V) -> ((K) -> V)

    memorized_0

    fn[V] memorized_0(f : () -> V) -> (() -> V)

    memorized_ignore_arg

    fn[K, V] memorized_ignore_arg(f : (K) -> V) -> ((K) -> V)

    not_eq

    fn[A : Eq] not_eq(x : A, y : A) -> Bool

    fn[A : Alt] or(x : A, y : A) -> A

    Alternative operator that combines two values of the same type implementing the Alt trait. This is equivalent to using the infix operator |.

    Parameters:

    • x : First value of type A that implements the Alt trait.
    • y : Second value of type A that implements the Alt trait.

    Returns the combined result after applying the alternative operation.

    Example:

    test "alt" {
    let a : Int? = Some(1)
    let b : Int? = Some(2)
    inspect!(@lib.or(a, b), content="Some(1)")
    let c : Int? = None
    inspect!(@lib.or(c, b), content="Some(2)")
    }

    or_opt

    fn[A] or_opt(a : A?, b : A?) -> A?

    or_opt_lazy

    fn[A] or_opt_lazy(a : A?, b : () -> A?) -> A?

    panic_with

    fn[N, A] panic_with(_n : N) -> A

    raise_exn

    fn[A, E : Error] raise_exn(a : E) -> A raise E

    randomRng

    fn randomRng() -> State[UInt64, UInt64]

    random_double

    fn random_double(min~ : Double = .., max~ : Double = ..) -> State[UInt64, Double]

    random_int

    fn random_int(min : Int, max : Int) -> State[UInt64, Int]

    random_with

    fn[A] random_with(gen : (UInt64) -> A) -> State[UInt64, A]

    safe_string_each

    fn safe_string_each(str : String, f : (Char) -> Unit) -> Unit

    safe_string_eachi

    fn safe_string_eachi(str : String, f : (Int, Char) -> Unit) -> Unit

    slice

    fn[Z : Slice + Length] slice(a : Z, start : Int, end : Int) -> Z

    slice_start

    fn[Z : Slice + Length] slice_start(a : Z, start : Int) -> Z

    source_loc

    fn source_loc(loc~ : SourceLoc = _) -> SourceLoc

    to_debug_string

    fn[T : Show] to_debug_string(val : T) -> String

    to_hex_string

    fn to_hex_string(num : Int, upper_case~ : Bool = ..) -> String

    Converts a non-negative integer to its hexadecimal string representation.

    Parameters:

    • num : The non-negative integer to convert.
    • upper_case : If true, uses uppercase letters (A-F) for hexadecimal digits; if false, uses lowercase letters (a-f). Defaults to false.

    Returns the hexadecimal string representation of the input number.

    Throws an error if the input number is negative.

    Example:

    test "to_hex_string" {
    // Basic conversion
    inspect!(to_hex_string(255), content="ff")
    inspect!(to_hex_string(255, upper_case=true), content="FF")

    // Zero case
    inspect!(to_hex_string(0), content="0")

    // Larger numbers
    inspect!(to_hex_string(0x1234), content="1234")
    }

    test "panic to_hex_string/negative" {
    let _ = to_hex_string(-1)

    }

    to_string

    fn[A : ToString] to_string(target : A) -> String

    unsafe_is

    fn[A, B] unsafe_is(a : A, b : B) -> Bool

    write_to_buffer

    fn[E : WriteToBuffer + Show] write_to_buffer(acc :
    T
    , e : E) -> Unit

    write_to_stringbuilder

    fn[E : WriteToStringBuilder + Show] write_to_stringbuilder(acc : StringBuilder, e : E) -> Unit