Type type

Type for types. F f(t:Type) ...; f(Arr) ...

Constructors

Type(name:Str, doc:Any, ns:Any)
Create a new type. Do not use directly.

Automatically called by NGS for syntax

type MyType
Type(t:Str, doc:Any, ns:Any, parent:Type) Source: stdlib.ngs:939
Create a new type. Do not use directly.

Automatically called by NGS for syntax

type MyType2(MyType1)
Type(t:Str, doc:Any, ns:Any, parents:Arr) Source: stdlib.ngs:944
Create a new type. Do not use directly.

Automatically called by NGS for syntax

type MyType2([MyParent1, MyParent2, ...])

Methods

.(t:Type, field:Str) Source: stdlib.ngs:3921
Undocumented
==(a:Type, b:Type)
Compare types. Implemented as sameness comparison.

Example

type T1; type T2; T1==T2  # false
decode(s:Str, t:Type)experimental Source: stdlib.ngs:971
Decode (parse) strings such as command line arguments or environment variables to result given type TODO: Consider renaming to UnArgv or decode_arg
ensure(x:Any, t:Type)experimental Source: stdlib.ngs:667
EXPERIMENTAL! Do not use! Makes sure returned value is of type t. If x is already of type t, returns x. Otherwise, returns object of type t with single item x.

Parameters

ta subtype of Eachable1

Returns

Object of type t
inherit(t:Type, parent:Type)
Make t inherit from parent. Do not use directly. Use "type MyType(parent)".

Returns

t

Example

type NotImplemented
NotImplemented.inherit(Exception)
init(e:InstantiatingAbstractType, t:Type) Source: stdlib.ngs:95
Initializes InstantiatingAbstractType.
init(p:AWS2::Parameter, res_type:Type, param_name:Str, param_value:Any) Source: autoload/AWS2.ngs:227
Undocumented
init(td:TypeDescription, containing_nd:NamespaceDescription, name:Str, type:Type)
Undocumented
is(obj:Any, t:Type)
Check whether obj is of type t. Uses same function that is used for matching arguments with method parameters when calling a method.

Returns

Bool

Example

1 is Int  # true
[] is Arr  # true
[] is Int  # false
is_subtype(t:Type, maybe_supertype:Type)experimental Source: stdlib.ngs:1006
Check whether t is a subtype of maybe_supertype. Note that if t and maybe_supertype are same type, this method also returns true. TODO: consider symbol <: as method name.

Returns

Bool

Example

Lines.is_subtype(Eachable1)  # true
Eachable.is_subtype(Lines)  # false
Pred(t:Type) Source: stdlib.ngs:272
Convert a type to a predicate.

Parameters

tA type

Returns

A function that checks whether the only argument is of type t
Str(t:Type) Source: stdlib.ngs:965
String representation of a type

Returns

"<Type NAME>"

Example

Real.Str().echo()  # Outputs: <Type Real>