Skip to content

Instantly share code, notes, and snippets.

@martinos
Forked from xymbol/foo_test.rb
Created March 22, 2017 15:22
Show Gist options
  • Save martinos/660affa48be27f9aa0c440a8e7c19166 to your computer and use it in GitHub Desktop.
Save martinos/660affa48be27f9aa0c440a8e7c19166 to your computer and use it in GitHub Desktop.
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
require "minitest/autorun"
module Foo
class << self
attr :add, :sub, :mul, :div
end
@add = -> (a, b) { a + b }.curry
@sub = -> (a, b) { a - b }.curry
@mul = -> (a, b) { a * b }.curry
@div = -> (a, b) { a / b }.curry
end
class FooTest < Minitest::Test
def test_add
assert_equal 5, Foo.add.(2).(3)
end
def test_add_with_curry
add2 = Foo.add.(2)
assert_equal 7, add2.(5)
end
def test_sub
assert_equal 5, Foo.sub.(7, 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment