Skip to content

Instantly share code, notes, and snippets.

@xymbol
Last active April 10, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xymbol/c6ad2812737e2d1b8f59213261bb3303 to your computer and use it in GitHub Desktop.
Save xymbol/c6ad2812737e2d1b8f59213261bb3303 to your computer and use it in GitHub Desktop.
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
require "minitest/autorun"
module Foo
attr :add, :sub, :mul, :div
def initialize(*)
@add = -> (a, b) { a + b }.curry
@sub = -> (a, b) { a - b }.curry
@mul = -> (a, b) { a * b }.curry
@div = -> (a, b) { a / b }.curry
super
end
end
class FooTest < Minitest::Test
include Foo
def test_add
assert_equal 3, add.(1, 2)
end
def test_add_sequence
assert_equal 5, add.(2).(3)
end
def test_add_with_curry
add2 = add.(2)
assert_equal 7, add2.(5)
end
def test_sub
assert_equal 5, sub.(7, 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment