Type type
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(x:Any)
Returns type of the given object Parameters
x Object. Currently only objects of NormalType are supported.
- Type(t:Str, doc:Any, ns:Any, parent:Type) Source: stdlib.ngs:111
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:116
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:2511
Undocumented Automatically called by NGS for syntax
SUBTYPE_OF_NAMEDINSTANCES.NamedInstances
Example
echo(Color.NamedInstances is Namespace) # true
- .(t:Type, field:Str) Source: stdlib.ngs:5818
Undocumented
- .=(t:Type, field:Str, ns:Namespace) Source: stdlib.ngs:2518
Undocumented Automatically called by NGS for syntax
SUBTYPE_OF_NAMEDINSTANCES.NamedInstances = ...
- .=(t:Type, field:Str, a:Arr) Source: stdlib.ngs:2537
Undocumented Automatically called by NGS for syntax
SUBTYPE_OF_NAMEDINSTANCES.NamedInstances = ['SOME', 'NAMES', ...]
- ::(t:Type, k:Str) Source: stdlib.ngs:2550
Undocumented Automatically called by NGS for syntax
SUBTYPE_OF_NAMEDINSTANCES::INSTANCE_NAME
Example
echo(Color::RED) # <Color numval=4 name=RED>
- <(t:Type, maybe_supertype:Type) Source: stdlib.ngs:2710
Similar to t <= maybe_supertype but returns false if t === maybe_supertype Returns
Bool
- <=(t:Type, maybe_supertype:Type) Source: stdlib.ngs:2695
Check whether t is maybe_supertype or its subtype Note that if t and maybe_supertype are same type, this method also returns true. Returns
BoolExample
Lines <= Eachable1 # true Eachable <= Lines # false
- ==(a:Type, b:Type) Source: stdlib.ngs:2684
Compare types. Same as a===b. Returns
Bool
- =~(x:Any, t:Type, _mc:MatchContext) Source: stdlib.ngs:1437
Check whether x is of type t Returns
x is t
- assert(f:Fun, t:Type, msg:Str='Assertion failed') Source: stdlib.ngs:373
Throws AssertFail with given function does not throw exception of the given type. Parameters
f Fun t Subtype of Exception Returns
The exceptionExample
assert({1/0}, DivisionByZero)
- code(t:Type) Source: stdlib.ngs:2730
Convert a type to NGS code that would produce the type. Not fully functional yet. Namespaces are not supported. Returns
Str
- decode(s:Str, t:Type) Source: stdlib.ngs:2161
Fallback for types without decode(). Throws DecodeFail.
- decode(value:Any, t:Type) Source: stdlib.ngs:2557
Resolve named instance of t by uniquely-identifying value of any field Example
echo("RED".decode(Color)) # <Color numval=4 name=RED>
- decode(s:Str, t:Type)experimental Source: stdlib.ngs:2653
Decode (parse) strings such as command line arguments or environment variables to result given type TODO: Consider renaming to UnArgv or decode_arg
- decode(s:Str, p:Type) Source: stdlib.ngs:6410
Decode Path and its subtypes Returns
instance of Path or a subtype.
- DynVar(t:Type) Source: stdlib.ngs:5840
DynVar of the type t: the same instance for the same t Example
DynVar(Namespace).get(null) # The namespace being defined, or null
- ensure(x:Any, t:Type)experimental Source: stdlib.ngs:1982
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
t a subtype of Eachable1 Returns
Object of type t
- ensure(x:Arr, t:Type) Source: stdlib.ngs:2104
Ensures x is of type t. Note that non-Arr x are handled in another implementation, ensure(x, t:Type), where t is Eachable1 or a subtype of Eachable1. Parameters
t ArrLike or a subtype of ArrLike Returns
An instance of type t, with elements from x.
- inherit(t:Type, parent:Type)
Make t inherit from parent. Do not use directly. Use "type MyType(parent)". Returns
tExample
type NotImplemented NotImplemented.inherit(Exception)
- init(e:InstantiatingAbstractType, t:Type) Source: stdlib.ngs:437
Initializes InstantiatingAbstractType.
- init(p:AWS2::Parameter, res_type:Type, param_name:Str, param_value:Any) Source: autoload/globals/AWS2.ngs:241
Undocumented
- init(td:TypeDescription, containing_nd:NamespaceDescription, name:Str, type:Type)
Undocumented
- instantiate_param_dflt(t:Type) Source: stdlib.ngs:2687
Returns t
- 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
BoolExample
1 is Int # true [] is Arr # true [] is Int # false
- is_subtype(t:Type, maybe_supertype:Type)deprecated Source: stdlib.ngs:2715
Use t <= maybe_supertype
- Str(t:Type) Source: stdlib.ngs:2643
String representation of a type Returns
"<Type NAME ...>"Example
Real.Str().echo() # Outputs: <Type Real with 3 constructor(s) and 1 meta entries>