Module: Fray
- Defined in:
- lib/fray/response_pipe.rb,
lib/fray/version.rb,
lib/fray/abortable_pipe.rb
Overview
Functor for handling errors as part of a chain of functions. Works much like the pipe operator |> from Elixir, but also handles responses. If a function within a ‘then` returns somethings that fulfills the initializing predicate, the remainder of the pipe will not be used. Rather, the `catch` function will be called (like with a JS promise). This function defaults to the identity function.
Anything that responds to #call can be passed to ‘then` or `catch` as an argument, including vanilla lambdas.
Examples:
AbortablePipe.new(->(v) { v.is_a?(Fray::Response) }).
then(->(x) { x + 1 }).
then(->(x, y) { x * y }, 2). # note how extra params are handled
catch(->(_) { 5 })
run(4)
Returns 10
AbortablePipe.new(->(v) { v.is_a?(Fray::Response) }).
abort_when().
then(->(x) { Fray::Response.new('hi') }).
then(->(x) { x * 2 }).
catch(->(_) { 5 })
run(4)
Returns 5
Defined Under Namespace
Modules: Data Classes: AbortablePipe, ResponsePipe
Constant Summary collapse
- VERSION =
'0.0.0-pre'