Stream.mapEffect(body => pipe(
Effect.all([
d1Parser(body),
d2Parser(body),
d3Parser(body),
], { mode: 'either'}),
Effect.andThen(([e1, e2, e3]) => {
if(Either.isRight(e1) && Option.isSome(e1.right)) {
return Option.getOrThrow(e1.right);
}
if(Either.isRight(e2) && Option.isSome(e2.right)) {
return Option.getOrThrow(e2.right);
}
if(Either.isRight(e3) && Option.isSome(e3.right)) {
return Option.getOrThrow(e3.right);
}
throw new Error('Could not parse event'); // <-- would like to return all errors from the parsers
}
))),
Stream.mapEffect(body => pipe(
Effect.all([
d1Parser(body),
d2Parser(body),
d3Parser(body),
], { mode: 'either'}),
Effect.andThen(([e1, e2, e3]) => {
if(Either.isRight(e1) && Option.isSome(e1.right)) {
return Option.getOrThrow(e1.right);
}
if(Either.isRight(e2) && Option.isSome(e2.right)) {
return Option.getOrThrow(e2.right);
}
if(Either.isRight(e3) && Option.isSome(e3.right)) {
return Option.getOrThrow(e3.right);
}
throw new Error('Could not parse event'); // <-- would like to return all errors from the parsers
}
))),