Return type
Example
{
F find_the_one(haystack:Arr, needle) {
ret_from_find_the_one = Return()
echo(ret_from_find_the_one)
haystack.each(F(elt) {
elt == needle throws ret_from_find_the_one("Found it!")
})
"Not found"
}
echo([10,20].find_the_one(20))
echo([10,20].find_the_one(30))
}
# Output:
# <Return closure=<UserDefinedMethod find_the_one at 1.ngs:2> depth=7 val=null>
# Found it!
# <Return closure=<UserDefinedMethod find_the_one at 1.ngs:2> depth=7 val=null>
# Not foundConstructors
- Return()
Get closure-specific Return type. Throwing it, will return from the closure Example
F f() Return(); f() # <Return closure=<UserDefinedMethod f at <command line -pi switch>:2> depth=4 val=null> F first(r:NumRange, predicate:Fun) { finish = Return() r.each(F(i) { predicate(i) throws finish(i) }) null }
Methods
- call(r:Return, v:Any=null) Source: stdlib.ngs:123
Implements calling of Return type instances like the finish(i) call in the example below Example
F first(r:NumRange, predicate:Fun) { finish = Return() r.each(F(i) { predicate(i) throws finish(i) }) null }