Skip to content

Instantly share code, notes, and snippets.

@matiasleidemer
Last active October 26, 2016 12:14
Show Gist options
  • Save matiasleidemer/2da9f5a71446c06ce1fad7d7cdf228cb to your computer and use it in GitHub Desktop.
Save matiasleidemer/2da9f5a71446c06ce1fad7d7cdf228cb to your computer and use it in GitHub Desktop.
require 'deterministic'
module ParamDecorator
module_function
extend Deterministic::Prelude::Result
# alias :>> :map
# alias :m :method # method returns a proc for a method
def call(params = [])
Success(params) >> method(:parse) >> method(:validate) >> method(:finished)
end
def parse(params)
params << "I parsed the params"
Success(params)
end
def validate(params)
params << "I validated the params"
Success(params)
end
def finished(params)
params << "I finished the params"
Success(params)
end
end
result = ParamDecorator.call
# puts result
puts result.class # Deterministic::Result::Success
puts result.value.join(' -> ') # I parsed the params -> I validated the params -> I finished the params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment