the_one multimethod

Methods

the_one(e:Eachable1, pattern:Any=method, body:Fun=method, found_more:Any=block, found_none:Any=block) Source: stdlib.ngs:1747
Find the only element that matches the pattern and execute given code with the value

Parameters

bodyThe code to execute when exactly one element that matches the pattern was found. Executed with the found value. It's value will be returned as result of the_one().
found_moreThe value to return when more than one element matches the pattern. If found_more is a Fun, the result of found_more() is returned instead. Defaults to throwing ElementNotFound.
found_noneThe value to return when none of the elements match the pattern. If found_none is a Fun, the result of found_none() is returned instead. Defaults to throwing ElementNotFound.

Returns

One of the following: body(the_element), Value(found_more), Value(found_none)

Example

F name(dn:MethodDocNode) {
	dn.children.the_one(MethodNameDocNode).text[0]
}