Skip to content

Find componentΒ #647

Open
Open
@emil14

Description

Almost same as #289 except

  1. Emits single elements instead of stream(s)
  2. 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!"

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions