Skip to content

feature suggestion: takeWhile() #275

Description

@wellcaffeinated

hey there. Great library!

A takeWhile() operator would be great.

Something like this?

const takeWhile = (predicate, inclusive = false) => async function* (iterable){
  for await (const res of iterable) {
    if (!await predicate(res)){
      if (inclusive){ yield res }
      return
    }
    yield res
  }
}
const count = [1, 2, 3, 4, 5, 6, 7]
await collect(takeWhile(x => x < 5)(count))
// => [1, 2, 3, 4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions