filter multimethod
Methods
- filter(e:Eachable1, pattern:Any=method) Source: stdlib.ngs:1117
Filter e using pattern. Parameters
e Eachable1. WARNING: instances of same type as e must have empty constructor and push() method. pattern When item =~ pattern returns true, the item will appear in the resulting array. Returns
Of same type as eExample
(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
predicate Test function to be called with one key and one value at a time. Returns
value of the same type as hlExample
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
h Source hash predicate Test 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
pattern Test 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 FailureExample
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
fExample
Failure("blah").filter(X>5) # <Failure val=blah>
- filter(rd:ResDef, predicate:Fun)
Create new resource definition by filtering resources of rd. Parameters
rd Original resource definition. Not modified. Returns
ResDefExample
# 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"