Module: Transproc::Conditional
- Extended by:
- Functions
- Defined in:
- lib/transproc/conditional.rb
Overview
Conditional transformation functions
Instance Method Summary collapse
-
#guard(value, predicate, fn) ⇒ Mixed
Apply the transformation function to subject if the predicate returns true, or return un-modified.
-
#is(value, type, fn) ⇒ Object
Calls a function when type-check passes.
Methods included from Functions
Instance Method Details
#guard(value, predicate, fn) ⇒ Mixed
Apply the transformation function to subject if the predicate returns true, or return un-modified
31 32 33 |
# File 'lib/transproc/conditional.rb', line 31 def guard(value, predicate, fn) predicate[value] ? fn[value] : value end |
#is(value, type, fn) ⇒ Object
Calls a function when type-check passes
51 52 53 |
# File 'lib/transproc/conditional.rb', line 51 def is(value, type, fn) guard(value, -> v { v.is_a?(type) }, fn) end |