Open
Description
Almost same as #289 except
- Emits single elements instead of stream(s)
- Emits result as soon as first element found and skips other elements
API
pub interface IFindHandler<T>(data T) (res bool)
pub component Find<T>(data stream<T>) (res T, miss any)) {
nodes { handler IFindHandler<T> }
// ...
}
Example usage
type Obj struct {
id int
name string
}
const objs list<Obj> = [
{ id: 1, name: "a" }
{ id: 2, name: "b" }
{ id: 3, name: "c" }
{ id: 42, name: "You found me!" }
{ id: 4, name: "d" }
]
component Main(start) (stop) {
nodes {
Find<Obj>{IsID42},
Println
}
:start -> ($objs -> find)
find:res -> println
find:miss -> ("not found :(" -> println)
println -> :stop
}
component IsID42(data Obj) (res bool) {
nodes { Eq }
:data.id -> eq:actual
42 -> eq:expected
eq -> :res
}
Output should be "You found me!"