filter multimethod

Methods

filter(e:Eachable1, pattern:Any=method) Source: stdlib.ngs:1117
Filter e using pattern.

Parameters

eEachable1. WARNING: instances of same type as e must have empty constructor and push() method.
patternWhen item =~ pattern returns true, the item will appear in the resulting array.

Returns

Of same type as e

Example

(1...10).filter(F(num) num % 2 == 0)  # Gives [2,4,6,8,10]
(1...10).filter(X<5)  # Gives [1,2,3,4]
filter(hl:HashLike, predicate:Fun) Source: stdlib.ngs:1678
Filter hash. Build new HashLike with kev-value pairs selected by predicate.

Parameters

predicateTest function to be called with one key and one value at a time.

Returns

value of the same type as hl

Example

my_hashlike.filter(F(k, v) k == 'a')
filter(h:Hash, predicate:Fun) Source: stdlib.ngs:3406
Filter a hash. Build new hash with kev-value pairs selected by the given predicate.

Parameters

hSource hash
predicateTest function to be called with one key and one value at a time: predicate(k, v)

Example

{'a': 1, 'b': 2}.filter(F(k, v) k == 'a')  # {'a': 1}
filter(fb:FullBox, pattern:Any=method) Source: stdlib.ngs:3782
Conditionally convert FullBox to EmptyBox.

Parameters

patternTest function or anything else acceptable by =~ to be called with the value in the FullBox, defaults to Bool.constructors

Returns

Box. fb if pattern succeeds, EmptyBox if not.

Example

Box(10).filter(X>5)   # <FullBox val=10>
Box(10).filter(X>20)  # <EmptyBox>
filter(s:Success, pattern:Any=method) Source: stdlib.ngs:3990
Check whether wrapped value matches the pattern.

Returns

s or Failure

Example

Success(10).filter(X>5)   # <Success val=10>
Success(10).filter(X>15)  # <Failure val=<ResultFail ...>>
filter(f:Failure, pattern:Any=method) Source: stdlib.ngs:3999
No-op, returns f

Returns

f

Example

Failure("blah").filter(X>5)  # <Failure val=blah>
filter(rd:ResDef, predicate:Fun)
Create new resource definition by filtering resources of rd.

Parameters

rdOriginal resource definition. Not modified.

Returns

ResDef

Example

# Get instances with last private IP octet less than 20:
AWS::Instance().filter({A.PrivateIpAddress.split(".")[-1].Int()<20})
filter(i:Iter, pattern:Any)
EXPERIMENTAL! Do not use!
filter(ds:DelimStr, pattern:Any)
Get new DelimStr with some elements filtered out

Example

DelimStr("/bin:/usr/bin:/usr/local/bin").filter(/usr/).Str()  # "/usr/bin:/usr/local/bin"