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/05077d8f87c667cac37f89ad02004333 to your computer and use it in GitHub Desktop.
Save martinos/05077d8f87c667cac37f89ad02004333 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
include Foo
def test_add
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
@xymbol
Copy link

xymbol commented Apr 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment