MCPcopy Create free account
hub / github.com/Effect-TS/effect / takeUntil

Function takeUntil

packages/effect/src/Sink.ts:1831–1850  ·  view source on GitHub ↗
(predicate: Predicate<In>)

Source from the content-addressed store, hash-verified

1829 * @since 4.0.0
1830 */
1831export const takeUntil = <In>(predicate: Predicate<In>): Sink<Array<In>, In, In> =>
1832 fromTransform((upstream) => {
1833 const out = Arr.empty<In>()
1834 return upstream.pipe(
1835 Effect.flatMap((arr) => {
1836 for (let i = 0; i < arr.length; i++) {
1837 out.push(arr[i])
1838 if (predicate(arr[i])) {
1839 const leftover: NonEmptyReadonlyArray<In> | undefined = (i + 1) < arr.length
1840 ? arr.slice(i + 1) as Arr.NonEmptyArray<In>
1841 : undefined
1842 return Cause.done([out, leftover] as const)
1843 }
1844 }
1845 return Effect.void
1846 }),
1847 Effect.forever({ disableYield: true }),
1848 Pull.catchDone((end) => Effect.succeed<End<Array<In>, In>>(end ?? [out]))
1849 )
1850 })
1851
1852/**
1853 * Collects input elements effectfully until the predicate returns `true`,

Callers 1

Stream.tsFile · 0.85

Calls 7

predicateFunction · 0.85
sliceMethod · 0.80
fromTransformFunction · 0.70
pipeMethod · 0.65
pushMethod · 0.65
doneMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected