-
-
Save martinos/660affa48be27f9aa0c440a8e7c19166 to your computer and use it in GitHub Desktop.
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
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 "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