Skip to content
heff

rune

Rune: a code point of Unicode, a 32-bit value, as Go’s rune is. A literal is written in quotes — 'a', 'é', '😀', a string’s escapes ('\n', '\'', '\\') or '\u{1F600}' — and is a Unicode scalar value: from U+0000 to U+10FFFF, but the surrogates, U+D800 to U+DFFF. A rune made of an integer may be any 32-bit value (fromInt, as Go’s rune(n)); one that is no scalar value is U+FFFD, replacement, in a string made of it (the prelude’s fromRunes), as what is not UTF-8 is where a string’s runes are read (runes). Import it by a name, import rune as Rune, as its names are the prelude’s: Rune.compare, Rune.max. Its operators, == to >=, are these too, for a module that imports it as it is and the prelude by a name. Its classes and cases are ASCII’s: isAlpha 'é' is False.

runeLt

runeLt : Rune -> Rune -> Bool

runeLe

runeLe : Rune -> Rune -> Bool

strRuneCount

strRuneCount : String -> Int

toInt

toInt : Rune -> Int

Its code point.

fromInt

fromInt : Int -> Rune

The rune of an integer, wrapped around to 32 bits as an Int32 is: fromInt 233 is 'é'.

replacement

replacement : Rune

U+FFFD, what a string has for a rune that is none (Go’s utf8.RuneError).

maxRune

maxRune : Rune

The last code point, U+10FFFF.

>>> List.map toInt ['a', 'é', '😀', maxRune, fromInt 4294967361]
[97, 233, 128512, 1114111, 65]

validCode

validCode : Int -> Bool

isValid

isValid : Rune -> Bool

Whether it is a Unicode scalar value: what a literal is, and what a string keeps as it is (Go’s utf8.ValidRune).

>>> List.map isValid [fromInt 55296, fromInt 1114112, fromInt -1, 'a']
[False, False, False, True]

width

width : Rune -> Int

How many bytes it is in a string: 1 to 4 (one that is no scalar value 3, as U+FFFD is; Go’s utf8.RuneLen).

>>> List.map width ['a', 'é', '中', '😀', fromInt 55296]
[1, 2, 3, 4, 3]

count

count : String -> Int

How many runes a string has, List.length (runes s) (Go’s utf8.RuneCountInString).

>>> List.map count ["", "héllo", "a😀", "\xffa"]
[0, 5, 2, 2]

foldl

foldl : {a : Type} -> (a -> Int -> Rune -> a) -> a -> String -> a

Its runes, each with where its bytes start, from the first (Go’s for i, r := range s).

>>> foldl (\acc i c -> acc ^ debug i ^ show c) "" "aé😀"
"0a1é3😀"

foldr

foldr : {a : Type} -> (Int -> Rune -> a -> a) -> a -> String -> a

Its runes, each with where its bytes start, from the last: f i1 r1 (f i2 r2 (… z)), as List.foldr goes.

>>> foldr (\i c acc -> acc ^ debug i ^ show c) "" "a\u{e9}\u{1F600}"
"3\u{1F600}1\u{e9}0a"

validString

validString : String -> Bool

Whether a string is UTF-8, each of its runes’ bytes (Go’s utf8.ValidString).

>>> List.map validString ["", "héllo", "\u{FFFD}", "\xe9", "\xc3"]
[True, True, True, False, False]

toValid

toValid : String -> String

The string, what is not UTF-8 in it U+FFFD, as runes reads it: fromRunes (runes s).

>>> runes (toValid "a\xffb")
['a', '\u{FFFD}', 'b']

eq

eq : Rune -> Rune -> Bool

lt

lt : Rune -> Rune -> Bool

le

le : Rune -> Rune -> Bool

compare

compare : Rune -> Rune -> Ordering

min

min : Rune -> Rune -> Rune

max

max : Rune -> Rune -> Rune

within

within : Rune -> Rune -> Rune -> Bool

isAscii

isAscii : Rune -> Bool

isDigit

isDigit : Rune -> Bool

'0' to '9'.

isHexDigit

isHexDigit : Rune -> Bool

A digit, or 'a' to 'f', 'A' to 'F'.

isUpper

isUpper : Rune -> Bool

isLower

isLower : Rune -> Bool

isAlpha

isAlpha : Rune -> Bool

A letter of ASCII’s, upper or lower case.

isAlphaNum

isAlphaNum : Rune -> Bool

isSpace

isSpace : Rune -> Bool

A space, a tab, a line feed, a carriage return, a vertical tab or a form feed.

>>> List.map isSpace (runes " \t\nx")
[True, True, True, False]

isControl

isControl : Rune -> Bool

A control character: C0’s, DEL, C1’s.

toUpper

toUpper : Rune -> Rune

'a' to 'z' in upper case; any other as it is.

>>> fromRunes (List.map toUpper (runes "héllo, wörld"))
"HéLLO, WöRLD"

toLower

toLower : Rune -> Rune

'A' to 'Z' in lower case; any other as it is.