3 ms·
this is nice, especially for the function clauses Elixir is my daily drive and working in Java made me miserable until I started working around the lack of pat
by peoplefromibiza 5y ago
this is nice, especially for the function clauses
Elixir is my daily drive and working in Java made me miserable until I started working around the lack of pattern matching facilities
Error handling is the worst part, I think a simple
switch (retval) {
Ok(val):
...
break;
Error(err):
...
would make Java much more pleasant, even without full pattern matching everywhere.
- crdrost 5y agoThis sorta exists in Java 17: sealed interface Result<T> permits Ok, Error {} record Ok<T>(value: T) implements Result<T> {} record Error<T>(error: Throwable) implements Result<T> {} // to consume switch (result) { case Error e -> e.error().getMessage(), case Ok v -> v.value().toString() }