Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I also made a library for working with `{:ok, value}` and `{:error, reason}` in Elixir: https://github.com/linkdd/rustic_result

Thanks to the pipeline operator and pattern matching, it makes pretty easy to read pipelines. It does not completely replace the with statement (that was not the point) but it simplified a lot of code.



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.


This 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()
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: