Last active
October 26, 2016 12:14
-
-
Save matiasleidemer/2da9f5a71446c06ce1fad7d7cdf228cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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