std/core¶
module core
The types every other module is written in: the scalars, the collection
types, the open tree Data, absence, failure, value order, the format
category and the core traits. A type sits here when a module below it
would otherwise import a module above it: Data is a tree of sequences
and maps, so the collection types are core types, and the operations
over them are the collections module's.
Orderable— A type whose values have a total order: of any two values of the type, one comes first or the two are equal.Scalar— A leaf: a value with no parts of its own.Bool— The truth valuestrueandfalse: aScalarwith equality and no order.Int— A 64-bit whole number, ordered by value:7 / 2is3, and7 % 2is1.Float— A 64-bit binary floating-point number, written with the suffixf(2.5f), ordered by value.Decimal— An exact decimal number, written with a decimal point and no suffix (2.50), ordered by value:0.1 + 0.2 == 0.3istrue.String— Text, ordered character by character:"ab" + "cd"is"abcd", and"hello"[1]is"e".Date— A calendar date, ordered by time.Iterable— A value whose elements can each be visited: the bound an operation states when it only visits each value.Collection— A finite multiset of occurrences, unordered, with no runtime representation.Stream— An ordered, possibly unending run of valuesx0, x1, x2, ....Seq— A finite stream: a collection in which every occurrence has exactly one position in0 .. size(c) - 1.List— A sequence of materialized occurrences; repeated traversal preserves positions.Set— Materialized distinct values under HQL equality:count(s, x) <= 1.Map— Materialized associations from distinct keys ofKto values ofV; not aCollection.OrderedMap— AMapwhose keys keep their construction positions: its keys are aSeq<K>.SortedMap— AnOrderedMapwhose key positions follow the intrinsic total order ofK.Data— An open tree whose keys belong to whoever wrote them: what a YAML or JSON document is.TypeContract— The supertype of a closed contract: a structural type declaredtype C : TypeContract = {…}has exactly its declared fields, and is validated as a contract.DataContract— The supertype of an open contract: a structural type declaredtype D : DataContract = {…}is a view overDatawith at least its declared fields, and is validated as a contract.Option— An optional value ofT: present, holding oneT, or absent.Result— A computation that may have failed:ok(value)with aT, orerr(error)with anE.Ordering— The result ofcompare(a, b):Less,EqualorGreater.Type— A type written as an argument:is(Card),of_type(Card).Format— The category of formats: how bytes are documents.Is— What a predicate that tests its parameter's type,x => x | is(U), gives: aBoolthat, where true, holds the parameter atU.Eq— Equality:a == banda != bover a type implementingEqcall itseq.Ord— Order:a < band the other comparisons over a type implementingOrdcall itscompare.Add— Addition:a + bover a type implementingAddisa.add(b).Sub— Subtraction:a - bover a type implementingSubisa.sub(b).Mul— Multiplication:a * bover a type implementingMulisa.mul(b).Div— Division:a / bover a type implementingDivisa.div(b).Rem— Remainder:a % bover a type implementingRemisa.rem(b).Range— A window of positions, what a slice takes:xs[a:b]isxs[Range(start = a, end = b)], and a bound left out is absent.Index— A position:xs[i]over a type implementingIndexisxs.at(i), the element there or its absence.Slice— A part:xs[a:b]over a type implementingSliceisxs.slice(Range(start = a, end = b)), a value of the type itself.Validator— A check a value passes: a trait extendingValidatoris a validator type.Operation— A function fromItoOthat also carries its shape: what an executor may assume about splitting the step.Elementwise— AnOperationwhose result for each element depends on that element alone, so it may run over any split of its input:mapandfilterare elementwise.Partition— AnOperationthat regroups its input by a key, each group running independently and completing in any order:groupis one.Reduction— AnOperationthat collapses its whole input to one value through a combiner the runtime holds, so each split may be reduced and the results combined:sizecombines by addition,containsby disjunction.Barrier— AnOperationthat needs its whole input before any output, so it is not split:sort,takeandreduceare barriers.Pair— Two values held together, each at its own type: whatzip,enumerate,entriesandjoinproduce, and whatPair(first = a, second = b)builds.Violation— One reason a value does not read as a contract, asvalidate(T)reports it.Invalid— A value that did not read as a contract, and every reason why: itscontract, thevalue, and theviolations.Diagnostic— A diagnostic a run delivered, read back as data: itsphase,kind,severityanddisposition, itsmessage, and where it points,originandspan, a{start, end}byte range.
Implementations¶
impl Eq for Bool
impl Eq for Int
impl Eq for Float
impl Eq for Decimal
impl Eq for String
impl Eq for Date
Bool, Int, Float, Decimal, String and Date compare with ==
by value.
impl Ord for Int
impl Ord for Float
impl Ord for Decimal
impl Ord for String
impl Ord for Date
Int, Float and Decimal are ordered by value, String character by
character, and Date by time.
impl Add for Int
impl Add for Float
impl Add for Decimal
impl Add for String
+ adds Ints, Floats and Decimals, and concatenates two
Strings: "ab" + "cd" is "abcd".
impl Sub for Int
impl Sub for Float
impl Sub for Decimal
- subtracts Ints, Floats and Decimals.
impl Mul for Int
impl Mul for Float
impl Mul for Decimal
* multiplies Ints, Floats and Decimals.
impl Div for Int
impl Div for Float
impl Div for Decimal
/ divides Ints, Floats and Decimals: 7 / 2 is 3.
impl Rem for Int
impl Rem for Float
impl Rem for Decimal
% is the remainder of Ints, Floats and Decimals: 7 % 2 is 1.
impl<T> Index<T> for Seq<T>
impl Index<String> for String
impl Index<Data> for Data
xs[i] over every sequence, a List among them, is the element at
i; over a String it is the character there, as text ("hello"[1]
is "e"); over Data it is the document's own element.
impl<T> Slice for Seq<T>
impl Slice for String
impl Slice for Data
xs[a:b] over every sequence, a String and Data is the part of the
same type: [1, 2, 3][1:] is [2, 3], and "hello"[1:3] is "el".