dflt multimethod

Methods

dflt(i:NormalTypeInstance, k:Any, v:Any) Source: stdlib.ngs:1052
Set object field if it's not already set

Returns

Field value, the already-existed or new.

Example

my_something.dflt(k, []).push(elt)
dflt(e:Eachable1, k:Any, v:Any) Source: stdlib.ngs:1066
Set a field on all elements if it's not already set

Parameters

eEachable1 with elements of type NormalTypeInstance or Hash

Returns

e

Example

my_items.dflt("source", "(unknown)")
dflt(hl:HashLike, k:Any, v:Any) Source: stdlib.ngs:1093
Set a key if it's not already set

Returns

Key value, the already-existed or new.

Example

mysomething.dflt(k, []).push(elt)
dflt(h:Hash, k:Any, v:Any) Source: stdlib.ngs:2756
Set a key in a Hash if it's not already set

Returns

Hash value, the already-existed or new.

Example

my_hash.dflt(k, []).push(elt)
dflt(fb:FullBox, x:Any) Source: stdlib.ngs:2975
Do nothing

Returns

fb

Example

my_array = [10, 20]
# dflt on FullBox has no effect
my_array.Box(1).dflt(100).map(X*2).each(echo) # HERE
# output: 40
# dflt on EmptyBox creates FullBox with the given value
my_array.Box(5).dflt(100).map(X*2).each(echo)
# output: 200
dflt(eb:EmptyBox, x:Any) Source: stdlib.ngs:2986
Wrap x in a Box

Returns

FullBox with the 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