An Elixir library for elegant error handling using result monads and result tuples.
OK is an Elixir library designed for elegant error and exception handling using result monads and result tuples. It solves the problem of managing errors in functional pipelines by providing macros and operators that work with `{:ok, value}` and `{:error, reason}` tuples, making error handling more explicit and composable.
Elixir developers building applications that require clean, functional error handling, especially those working with pipelines or frameworks like Raxx.
Developers choose OK for its concise syntax, focus on result tuples without catching raised errors, and its functional approach that integrates seamlessly with Elixir's pattern matching and piping capabilities.
Elegant error/exception handling in Elixir, with result monads.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Treats result tuples as monads with operators like `~>>` and `~>` for flat_map and map, enabling clean, functional error chaining in pipelines as shown in the OK Pipe examples.
Macros such as `OK.for` and `OK.try` simplify combining functions that may fail, using `<-` for extraction and custom rescue blocks, reducing boilerplate in error-prone code.
Focuses on explicit error handling through result tuples without catching raised errors, promoting predictable code as per the philosophy that errors are not exceptional.
Works well with frameworks like Raxx via `OK.try` for building HTTP responses based on error cases, making it suitable for web applications with custom error representations.
Only supports `{:ok, value}` and `{:error, reason}` tuples; other error shapes require manual wrapping, as admitted in the FAQ, adding overhead for non-standard functions.
Deliberately avoids catching exceptions, meaning it cannot handle errors raised within functions without extra `try/rescue` blocks, limiting use in mixed error-handling environments.
Requires understanding of monadic patterns and functional programming, which may pose a learning curve for developers unfamiliar with these concepts beyond basic Elixir.
Version 2.0 introduced deprecations like `OK.with` and renames such as `OK.bind` to `OK.flat_map`, potentially disrupting existing codebases and requiring migration effort.