Transmute
a framework for writing functional helpers in ruby
Installation
gem 'transmute'
Usage
require 'transmute'
# Transmute provides a very light weight framework for definining
# helpers in a functional, chainable manner
#
# To define a function, simply add an instance method to Transmute::Definition
Transmute::Definition.module_eval do
def increment(value, n = 1)
value + n
end
end
# The methods you add to Transmute::Definition can then be used via the Transmute
# module
[1, 2, 3].map(&Transmute.increment)
#=> [2, 3, 4]
[1, 2, 3].map(&Transmute.increment).map(&Transmute.increment)
#=> [3, 4, 5]
[1, 2, 3].map(&Transmute.increment(2))
#=> [3, 4, 5]
TODO
- support some pattern matching-esque format (e.g. ```rb on Integer def increment(value, n = 1) value + n end
on String def increment(value, n = 1) value.to_i + n end
on -> (value) { value.is_a?(Array) && value.all? { |v| v.is_a?(Integer) } } def increment(value, n = 1) # Should recurse into other patterns value.map(&Transmute.increment(n)) end
)