The first match through a stream pipeline
The complete source of flowControl_first_match.ek9, compiled by the EK9 compiler. Shown on flowControl.html.
#!ek9 defines module site.flowControl.firstmatch defines function startsWithA() as pure -> item as String <- rtn as Boolean: item matches /^A.*/ defines program FirstMatch() stdout <- Stdout() items <- ["Beta", "Alpha", "Avocado"] firstMatch <- cat items | filter by startsWithA | head 1 | collect as List of String found <- not firstMatch.empty() stdout.println(found)
Download flowControl_first_match.ek9
Output
true