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

Function flattenExitOption

packages/effect/src/internal/stream.ts:2905–2953  ·  view source on GitHub ↗
(
  self: Stream.Stream<Exit.Exit<A, Option.Option<E2>>, E, R>
)

Source from the content-addressed store, hash-verified

2903
2904/** @internal */
2905export const flattenExitOption = <A, E2, E, R>(
2906 self: Stream.Stream<Exit.Exit<A, Option.Option<E2>>, E, R>
2907): Stream.Stream<A, E | E2, R> => {
2908 const processChunk = (
2909 chunk: Chunk.Chunk<Exit.Exit<A, Option.Option<E2>>>,
2910 cont: Channel.Channel<Chunk.Chunk<A>, Chunk.Chunk<Exit.Exit<A, Option.Option<E2>>>, E | E2, E, unknown, unknown, R>
2911 ) => {
2912 const [toEmit, rest] = pipe(chunk, Chunk.splitWhere((exit) => !Exit.isSuccess(exit)))
2913 const next = pipe(
2914 Chunk.head(rest),
2915 Option.match({
2916 onNone: () => cont,
2917 onSome: Exit.match({
2918 onFailure: (cause) =>
2919 Option.match(Cause.flipCauseOption(cause), {
2920 onNone: () => core.void,
2921 onSome: core.failCause
2922 }),
2923 onSuccess: () => core.void
2924 })
2925 })
2926 )
2927 return pipe(
2928 core.write(pipe(
2929 toEmit,
2930 Chunk.filterMap((exit) =>
2931 Exit.isSuccess(exit) ?
2932 Option.some(exit.value) :
2933 Option.none()
2934 )
2935 )),
2936 core.flatMap(() => next)
2937 )
2938 }
2939 const process: Channel.Channel<
2940 Chunk.Chunk<A>,
2941 Chunk.Chunk<Exit.Exit<A, Option.Option<E2>>>,
2942 E | E2,
2943 E,
2944 unknown,
2945 unknown,
2946 R
2947 > = core.readWithCause({
2948 onInput: (chunk: Chunk.Chunk<Exit.Exit<A, Option.Option<E2>>>) => processChunk(chunk, process),
2949 onFailure: (cause) => core.failCause<E | E2>(cause),
2950 onDone: () => core.void
2951 })
2952 return new StreamImpl(pipe(toChannel(self), core.pipeTo(process)))
2953}
2954
2955/** @internal */
2956export const flattenIterables = <A, E, R>(self: Stream.Stream<Iterable<A>, E, R>): Stream.Stream<A, E, R> =>

Callers 2

flattenTakeFunction · 0.85
stream.tsFile · 0.85

Calls 4

processChunkFunction · 0.85
failCauseMethod · 0.80
pipeFunction · 0.70
toChannelFunction · 0.70

Tested by

no test coverage detected