first multimethod

Methods

first(e:Eachable1, pattern:Any=method, dflt:Any=block) Source: stdlib.ngs:1556
Find first element in e that matches the pattern.

Parameters

patternTest function or anything else acceptable by =~, defaults to Bool.constructors

Returns

Either the element or the provided default if element was not found.

Example

(10..20).first(F(x) x % 3 == 0)        # 12 - first item divisible by 3
(10..20).first(F(x) x % 50 == 0, 1000) # 1000
[false, 0, null, "xyz", 100].first()  # "xyz"
[].first()                            # ElementNotFound exception