Last active
April 10, 2017 17:07
-
-
Save xymbol/c6ad2812737e2d1b8f59213261bb3303 to your computer and use it in GitHub Desktop.
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
This file contains hidden or 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 "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