Module: Philiprehberger::Result::Filterable
Overview
Filtering support for Ok and Err results.
Instance Method Summary collapse
-
#filter(error_fn) {|value| ... } ⇒ Ok, Err
If Ok and predicate fails, convert to Err with the given error.
Instance Method Details
#filter(error_fn) {|value| ... } ⇒ Ok, Err
If Ok and predicate fails, convert to Err with the given error. If already Err, pass through unchanged.
13 14 15 16 17 18 |
# File 'lib/philiprehberger/result/filterable.rb', line 13 def filter(error_fn, &block) return self if err? return self if block.call(@value) Err.new(error_fn.call) end |