Skip to content

aivi.core.bytes ​

aivi.core.bytes provides immutable byte sequences. Its operations are synchronous and pure. Indexes and lengths count bytes rather than Unicode characters.

Type class operations ​

Bytes implements Semigroup, Monoid, and Default through this module. Ambient append concatenates bytes; empty and default produce empty bytes. The module's explicitly imported append and empty helpers have the same behavior.

API ​

ExportTypeBehavior
emptyBytesThe empty byte sequence
lengthBytes -> IntCount bytes
getInt -> Bytes -> Option IntRead a byte from zero through 255
sliceInt -> Int -> Bytes -> BytesReturn the half-open byte range [from, to) with bounds clamped
appendBytes -> Bytes -> BytesConcatenate two byte sequences
fromTextText -> BytesEncode UTF-8
toTextBytes -> Option TextDecode UTF-8, returning None for invalid data
repeatInt -> Int -> BytesRepeat a byte value a requested number of times
isEmptyBytes -> BoolTest whether the sequence has zero bytes
nonEmptyBytes -> BoolTest whether the sequence has at least one byte
concatList Bytes -> BytesConcatenate a list of byte sequences

repeat requires a byte value in the range zero through 255. A nonpositive repeat count returns empty.

aivi
use aivi.core.bytes (
    append
    fromText
    toText
)

value payload : Bytes = append (fromText "hello") (fromText "!")
value decoded : Option Text = toText payload

(c) 2026 by Andreas Herd