Module: Transproc::Composer

Defined in:
lib/transproc/composer.rb

Overview

Helper extension handy for composing many functions in multiple steps

Examples:

include Transproc::Composer

fn = compose do |fns|
  fns << t(:map_array, t(:symbolize_keys))
  fns << t(:map_array, t(:nest, :address, [:city, :zipcode]))
end

fn.call [{ 'city' => 'NYC', 'zipcode' => '123' }]
# => [{ address: { city: 'NYC', zipcode: '123' }]

Defined Under Namespace

Classes: Factory

Instance Method Summary collapse

Instance Method Details

#compose(default = nil) {|factory| ... } ⇒ Object

Gather and compose functions and fall-back to a default one if provided

Examples:

include Transproc::Composer

fn = compose(-> v { v }) do |fns|
  fns << t(:to_string) if something
end

fn[1] # => "1"

Yields:

  • (factory)

See Also:



63
64
65
66
67
# File 'lib/transproc/composer.rb', line 63

def compose(default = nil)
  factory = Factory.new(default)
  yield(factory)
  factory.to_fn
end