Struct of These #1648
-
Given a structure where each property is of type declare const someStruct: {
a1: TH.These<E1, A1>;
a2: TH.These<E2, A2>;
a3: TH.These<E3, A3>;
} I'm treating
Now I'm looking for a way to combine results of a struct like the one above. Basically I want to do a Approachconst someStruct = { function getLastSemigroup<A = never>(): SG.Semigroup { const apply = TH.getApply<string | number>(getLastSemigroup()); pipe( Edited for clarity |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There's two issues here, from what I can tell. First, in
to filter out the props with type never, but do you actually need this? I would assume most of the time you have a For the second point you're missing one crucial step. How are you going to retain all the left values, if your
If you can't control how your Also, just for reference, here's how
|
fab \ fa |
left |
right |
both |
---|---|---|---|
left |
left(S.concat(fab.left, fa.left) |
left(fab.left) |
left(S.concat(fab.left, fa.left)) |
right |
left(fa.left) |
right(fab.right(fa.right)) |
both(fa.left, fab.right(fa.right)) |
both |
left(S.concat(fab.left, fa.left)) |
both(fab.left, fab.right(fa.right)) |
both(S.concat(fab.left, fa.right), fab.right(fa.right)) |
Which is what you want: If even a single fa
is a left
, you won't be able to recover, and you'll end up with a left, which includes all errors, minor and major. If all your 'fa's are right
, you'll end up with a right
, and if some of them are both
you'll end up with a both
, something like { left: [... errors ...], right: { a1: 1, a2: 'foobar' } }
.
Beta Was this translation helpful? Give feedback.
There's two issues here, from what I can tell. First, in
TH.map((s) => ...)
,s
is{ a1: number; a2: never; a3: string }
, including the irksomea2: never
. You could use a helper type like this:to filter out the props with type never, but do you actually need this? …