Module: AbstractMapper::Functions Private
- Extended by:
- Transproc::Registry
- Defined in:
- lib/abstract_mapper/functions.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
The collection of gem-specific pure functions (transproc)
Instance Method Summary collapse
-
#compact(array, fn) ⇒ Array
private
Applies the function to every consecutive pair of array elements, and removes empty values.
-
#filter(array, fn) ⇒ Array
private
Applies the function to every element of array and removes empty values.
-
#subclass?(subling, ancestor) ⇒ Boolean
private
Checks whether the class or module has given ancestor.
Instance Method Details
#compact(array, fn) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies the function to every consecutive pair of array elements, and removes empty values
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/abstract_mapper/functions.rb', line 47 def compact(array, fn) array.each_with_object([]) do |i, a| if a.empty? a << i else a[-1] = fn.call(a.last, i) a.flatten! end end end |
#filter(array, fn) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies the function to every element of array and removes empty values
27 28 29 |
# File 'lib/abstract_mapper/functions.rb', line 27 def filter(array, fn) map_array(array, fn).compact.flatten end |
#subclass?(subling, ancestor) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks whether the class or module has given ancestor
70 71 72 |
# File 'lib/abstract_mapper/functions.rb', line 70 def subclass?(subling, ancestor) subling.ancestors.include?(ancestor) end |