Skip to content

Instantly share code, notes, and snippets.

@he9lin
Created July 16, 2015 16:05
Show Gist options
  • Save he9lin/4607bbafd1b9948df6a6 to your computer and use it in GitHub Desktop.
Save he9lin/4607bbafd1b9948df6a6 to your computer and use it in GitHub Desktop.
Fun with deterministic gem
require 'deterministic'
module Deterministic
module Monad
alias :>= :fmap
end
end
class Foo
include Deterministic
include Deterministic::Prelude::Result
alias :m :method # method conveniently returns a Proc to a method
def call(params)
Success(params) >>
m(:validate).curry['x'] >>
m(:send).curry['y'] >=
m(:report)
end
def validate(a, params)
Success(params + a)
end
def send(a, params)
Success(params + a)
end
def report(params)
params + 'report'
end
def calculate
Success(1) >= m(:plus_one)
end
def plus_one(n)
n += 1
end
end
p Foo.new.call('data')
p Foo.new.calculate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment