Skip to content

aivi.prelude

The aivi.prelude module is AIVI's convenience layer — it re-exports the most commonly used functions from across the standard library so you can access them all from a single import.

It also serves as the source of built-in types and type classes such as Int, Bool, Text, List, Option, Result, and type class constraints like Eq, Ord, Functor, and more.

Usage

aivi
use aivi.prelude (
    Int
    Bool
    Text
    List
    getOrElse
    withDefault
    length
    head
    min
    max
    join
)

Built-in Types

These types are always available and can be imported from aivi.prelude:

TypeDescription
Int64-bit signed integer
Float64-bit floating point
DecimalArbitrary-precision decimal
BigIntArbitrary-precision integer
BoolBoolean: True or False
TextUnicode text string
UnitThe unit type (no value)
OrderingResult of comparison: Less, Equal, or Greater
List AOrdered collection
Option AOptional value: Some value or None
Result E ASuccess or failure: Ok value or Err error
Validation E AAccumulating validation: Valid value or Invalid errors
Signal AA reactive value that changes over time
Task E AAn async computation

Type Classes

ClassDescription
Eq AEquality comparison
Ord AOrdering and comparison
Default AA default value
Functor FMappable container
Applicative FApplicative functor
Monad FMonadic chaining (List, Option, and Result are the builtin executable carriers today)
Foldable FFoldable container
Traversable FTraversable container
Filterable FFilterable container
Semigroup AAssociative combination
Monoid ASemigroup with identity
Bifunctor FMappable over both type parameters

For the current higher-kinded hierarchy, the executable builtin carrier matrix, and the current same-module-only limits for user-authored higher-kinded classes and instances, see Typeclasses & Higher-Kinded Support. Parser or checker acceptance alone does not imply executable runtime support.

Option Functions

aivi
use aivi.prelude (
    getOrElse
    isSome
    isNone
    mapOption
    filterOption
)

value name : Option Text = Some "Ada"
value displayName : Text = getOrElse "guest" name
value hasName : Bool = isSome name

Result Functions

aivi
use aivi.prelude (
    withDefault
    isOk
    isErr
)

value age : Result Text Int = Ok 30
value ageValue : Int = withDefault 0 age
value succeeded : Bool = isOk age

List Functions

aivi
use aivi.prelude (
    length
    head
    isEmpty
    nonEmpty
    reverse
    take
)

value items : List Text = [
    "Ada",
    "Grace",
    "Hedy"
]

value count : Int = length items
value first : Option Text = head items
value empty : Bool = isEmpty []

Order Functions

aivi
use aivi.prelude (
    min
    max
    minOf
)

type Int -> Int -> Bool
func earlier = a b =>
    a < b

value smallest : Int = min earlier 5 3
value greatest : Int = max earlier 5 3

value leastOf : Int =
    minOf earlier 10 [
        7,
        4,
        9
    ]

Text Functions

aivi
use aivi.prelude (
    join
    surround
)

value csv : Text =
    join ", " [
        "Ada",
        "Grace",
        "Hedy"
    ]

value combined : Text =
    join "" [
        "Hello",
        " ",
        "World"
    ]

value wrapped : Text = surround "(" ")" "AIVI"

Math Functions

aivi
use aivi.prelude (
    abs
    negate
    isEven
    clamp
    between
)

value absolute : Int = abs (-5)
value flipped : Int = negate 7
value even : Bool = isEven 4
value clamped : Int = clamp 0 100 150
value inRange : Bool = between 1 10 5

Bool Functions

aivi
use aivi.prelude (
    not
    xor
    implies
)

value inverted : Bool = not True
value exclusive : Bool = xor True False

Pair Functions

aivi
use aivi.prelude (
    fst
    snd
    swap
)

value pair : (Int, Text) = (
    42,
    "hello"
)

value first : Int = fst pair
value second : Text = snd pair
value swapped : (Text, Int) = swap pair

AIVI Language Manual