Std.Shape
enum ShapeThe shape of a type. The variants are named after the types they describe (Int, List), and
are meant to be written with the module (Shape.Int): Bool is also a variant of Dynamic.
-
Bool -
Int -
Int64 -
Float -
String -
Bytes -
AnyAny value (
Dynamicitself). -
List(Shape) -
Option(Shape) -
Map(key: Shape, value: Shape) -
Record(name: String, fields: List[Field])A type with fields, by the name of the type. The name of a type with type parameters carries its type arguments (
generic_name). -
Variants(name: String, variants: List[Variant])An enum, by the name of the enum, named as for
Record. -
Ref(String)A type that appears again inside itself, by its name (
Node(left: Tree, ...)). -
Named(name: String, shape: Shape)A type known by its name, with the shape of its contents: an opaque type whose constructor checks the contents (
Quantity, an Int of at least 1). -
Annotated(shape: Shape, notes: List[(String, Dynamic)])shapewith notes on it. The notes of this module are written withdescription,minimumand the other functions below; a reader passes on the keys it does not know.
type Field(name: String, shape: Shape)A field of a record or of named contents.
name: Stringshape: Shape
Variant
Section titled “Variant”type Variant(name: String, contents: Contents)A variant of an enum, with the contents in the form it is declared in.
name: Stringcontents: Contents
Contents
Section titled “Contents”enum ContentsThe contents of a variant, in the form they are declared in: none, positional or named.
NoFieldsPositionalFields(List[Shape])NamedFields(List[Field])
Shaped
Section titled “Shaped”trait ShapedA type whose shape is known. proxy only carries the type: a trait function selects its impl
from the types of its arguments, and there is no way to write the type argument at the call.
Write p: Option[User] = None and call Shaped.shape(p), or use of_value and of_parameter.
An impl writes shape_in. visiting holds the names of the records and enums being read
around this one, innermost first: a type already there is written as Ref instead of being
read again, so types that refer to each other (Team with a Member, Member with a Team)
end. visit does this for a named type; an impl for a type with type arguments passes
visiting on to them.
-
fn shape_in(proxy: Option[Self], visiting: List[String]) -> ShapeThe shape of the type of
proxy, withvisitingthe names of the records and enums being read around it. -
fn shape(proxy: Option[Self]) -> ShapeThe shape of the type of
proxy. Callsshape_inwith an emptyvisiting.
fn visit(name: String, visiting: List[String], build: fn(List[String]) -> Shape fails E(build) uses { R(build) }) -> Shape fails E(build) uses { R(build) }The shape of the record or enum name: Ref(name) if it is already being read in
visiting, otherwise build with name added to visiting.
impl Team: Shaped { fn shape_in(proxy, visiting) { Shape.visit("Team", visiting, |visiting| { lead: Option[Member] = None Record(name: "Team", fields: [Field(name: "lead", shape: Shaped.shape_in(lead, visiting))]) }) }}of_value
Section titled “of_value”fn of_value[A: Shaped](value: A) -> ShapeThe shape of the type of value.
of_parameter
Section titled “of_parameter”fn of_parameter[A: Shaped, B, E, R](f: fn(A) -> B fails E uses { R }) -> ShapeThe shape of the parameter of f, without calling it. A router reads the type of the input
of a handler this way.
annotate
Section titled “annotate”fn annotate(shape: Shape, name: String, value: Dynamic) -> Shapeshape with the note name added after its notes. A note of the same name already there is
replaced.
description
Section titled “description”fn description(shape: Shape, text: String) -> ShapeA description for people.
pattern
Section titled “pattern”fn pattern(shape: Shape, regex: String) -> ShapeA regular expression that a string matches. Only described.
format
Section titled “format”fn format(shape: Shape, name: String) -> ShapeThe name of a known form of string ("date-time", "email", "uuid"). Only described, as for
pattern.
minimum
Section titled “minimum”fn minimum(shape: Shape, n: Int) -> ShapeThe least number allowed. Only described, as are the notes below: nothing in this module checks them.
maximum
Section titled “maximum”fn maximum(shape: Shape, n: Int) -> ShapeThe greatest number allowed.
min_length
Section titled “min_length”fn min_length(shape: Shape, n: Int) -> ShapeThe least length of a string, counted in code points.
max_length
Section titled “max_length”fn max_length(shape: Shape, n: Int) -> ShapeThe greatest length of a string, counted in code points.
min_items
Section titled “min_items”fn min_items(shape: Shape, n: Int) -> ShapeThe least number of items of a list.
max_items
Section titled “max_items”fn max_items(shape: Shape, n: Int) -> ShapeThe greatest number of items of a list.
fn strip(shape: Shape) -> Shapeshape without its notes and names: what its values are made of.
fn note(shape: Shape, name: String) -> Option[Dynamic]The value of the note name on shape, looking through names, or None.
field_names
Section titled “field_names”fn field_names(shape: Shape) -> List[String]The names of the fields of a record, in declared order, looking through notes and names. Empty for any other shape.
name_of
Section titled “name_of”fn name_of(shape: Shape) -> StringThe name of shape as a type is written: Int, List[String], Page[Member]. Notes are not
part of it.
generic_name
Section titled “generic_name”fn generic_name(name: String, arguments: List[Shape]) -> StringThe name of a type with type parameters, from its name and the shapes of its type arguments:
generic_name("Page", [member]) is "Page[Member]". Without arguments, name as it is.