EmptyBox type

Represents absence of a value

Direct parent types

Box
A box which might (FullBox) or might not (EmptyBox) contain a value. Box is somewhat similar to Arr of zero (EmptyBox) or exactly one (FullBox) element. This analogy helps understanding each() and filter() operation.
Direct subtypes: 2
NoData
Absence of data
Direct subtypes: 2

Methods

Bool(eb:EmptyBox) Source: stdlib.ngs:4524
Always false
dflt(eb:EmptyBox, x:Any) Source: stdlib.ngs:4674
Wrap x in a Box

Parameters

xThe value for the FullBox. If x is a Fun, the result of x() is used instead.

Returns

FullBox(Value(x))

Example

my_array = [10, 20]
# dflt on FullBox has no effect
my_array.Box(1).dflt(100).map(X*2).each(echo)
# output: 40
# dflt on EmptyBox creates FullBox with the given value
my_array.Box(5).dflt(100).map(X*2).each(echo) # HERE
# output: 200
each(eb:EmptyBox, cb:Fun) Source: stdlib.ngs:4548
Do nothing

Returns

eb

Example

Box(null).each(echo)  # No output
get(eb:EmptyBox) Source: stdlib.ngs:4583
Get EmptyBox value. Always throws BoxFail.
get(eb:EmptyBox, dflt:Any) Source: stdlib.ngs:4592
Get EmptyBox value

Parameters

dfltDefault value. If dflt is a Fun, the result of dflt() is used instead.

Returns

Value(dflt)

Example

EmptyBox().get(10)  # 10
EmptyBox().get({ 5 + 5 })  # 10
JsonData(eb:EmptyBox) Source: stdlib.ngs:4697
Convert EmptyBox into JSON compatible data structure - null
len(eb:EmptyBox) Source: stdlib.ngs:4603
Length of EmptyBox

Returns

0
map(eb:EmptyBox, mapper:Fun) Source: stdlib.ngs:4538
Do nothing

Returns

eb

Example

EmptyBox().map(X*2)  # <EmptyBox>