Module: Transproc::Recursion
- Extended by:
- Functions
- Defined in:
- lib/transproc/recursion.rb
Overview
Recursive transformation functions
Constant Summary collapse
- IF_ARRAY =
-> fn { Transproc(:is, Array, fn) }
- IF_HASH =
-> fn { Transproc(:is, Hash, fn) }
Instance Method Summary collapse
-
#array_recursion(value, fn) ⇒ Array
Recursively apply the provided transformation function to an array.
-
#hash_recursion(value, fn) ⇒ Hash
Recursively apply the provided transformation function to a hash.
Methods included from Functions
Instance Method Details
#array_recursion(value, fn) ⇒ Array
Recursively apply the provided transformation function to an array
37 38 39 40 41 42 43 44 |
# File 'lib/transproc/recursion.rb', line 37 def array_recursion(value, fn) result = fn[value] guarded = IF_ARRAY[-> v { Transproc(:array_recursion, fn)[v] }] result.map! do |item| guarded[item] end end |
#hash_recursion(value, fn) ⇒ Hash
Recursively apply the provided transformation function to a hash
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/transproc/recursion.rb', line 59 def hash_recursion(value, fn) result = fn[value] guarded = IF_HASH[-> v { Transproc(:hash_recursion, fn)[v] }] result.keys.each do |key| result[key] = guarded[result.delete(key)] end result end |