fun
fun copied to clipboard
Move away from widen functions
Remove widen from the library and make the default exports for all ADTs widen where appropriate. The canonical algebraic structure exports will have tighter types.
There is a reason for widening that is also appearing in the fetch_archive, which in production code is quite often coming up, because an operation will often yield a discriminated union of errors by adding different errors down the chain.
What other means of dealing with widening the left side could we come up with?
Generally those issues come up in any function that can remap the left hand side of an ADT extending Either. My thought was to simply update the base exported functions with widening in their types. For example,
export function chain<A, I, J>(
fati: (a: A) => Either<J, I>,
): ((ta: Either<B, A>) => Either<B | J, I>) {
return (ta) => isLeft(ta) ? ta : fati(ta.right);
}
This would make the working exports from each ADT have type widening built in, but the canonical "Type Class" exports would have type narrowing, which is what you want if you're taking a general Monad and extending it. Thoughts?
Auto-widening the Left side in chaining is desirable and saves us from having to implement a specific chainW or bindW where fp-ts went. I would reason here that it's logical that a different operation can have a different Left side.