-
Notifications
You must be signed in to change notification settings - Fork 10
simple match function on rune #790
Comments
Yes, a |
Good point, especially since |
In addition to a const isType = isTagged("type")
rune
.handle(isType("Id"), () => {})
.handle(isType("Address20"), () => {}) |
I'm playing with this on my branch to see if it improves my control flow. Impl was surprisingly simple, but it'll be better typed when it's its own match<T2 extends T, T3, U3>(
fn: Guard<T, T2>,
alt: (rune: ValueRune<T2, never>) => Rune<T3, U3>,
): ValueRune<T | T3, U | U3> {
return this.unhandle(fn).rehandle(fn as Guard<T2 | U, T2>, alt)
} |
The issue with that implementation is that it may unintentionally rehandle values; part of the reason to have a |
If you have a param that's a or Rune<T | Uint8Array | undefined> or any other typescript union, and you'd like to treat each case separately, you'd have to do some combination of
.unhandle(isUint8Array)
and.rehandle(isUint8Array, $encoder.encode)
for each separate type.Would be nice to have a simple match that does the same thing, but with a more understandable control flow:
related to #624 , but for general conditional control flows based on any arbitrary value
The text was updated successfully, but these errors were encountered: