Would be great if typescript allows pattern matching, then you’ll do
with(result){ Err(e) => console.log(“error!”); Ok(value) => console.log(value); }
Rust flavor here
Yes, that's nice. There are a couple of functional languages that support it. E.g. Erlang where I first saw this in action.
Maybe one day!
Actually you can do something similar:
blog.logrocket.com/pattern-matchin...
It’s not as pretty as real pattern matching but it fits to this use car.
github.com/gvergnaud/ts-pattern
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Would be great if typescript allows pattern matching, then you’ll do
Rust flavor here
Yes, that's nice. There are a couple of functional languages that support it. E.g. Erlang where I first saw this in action.
Maybe one day!
Actually you can do something similar:
blog.logrocket.com/pattern-matchin...
It’s not as pretty as real pattern matching but it fits to this use car.
github.com/gvergnaud/ts-pattern