spec/monad_spec.rb in ribimaybe-0.0.12 vs spec/monad_spec.rb in ribimaybe-0.0.13

- old
+ new

@@ -15,54 +15,56 @@ let(:g) do ->(x){ ->(y) { rturn(x) } }.(SecureRandom.base64(1000)) end - # return a >>= f = f a - describe "left identity" do - context "when i have nothing" do - it do - expect(Nothing.bind(&lifted_id)).to eq(Nothing) + [:bind, :>=].each do |m| + # return a >>= f = f a + describe "left identity" do + context "when i have nothing" do + it do + expect(Nothing.public_send(m, &lifted_id)).to eq(Nothing) + end end - end - context "when i have just :x" do - it do - expect(rturn(:x).bind(&lifted_id)).to eq(lifted_id.(:x)) + context "when i have just :x" do + it do + expect(rturn(:x).public_send(m, &lifted_id)).to eq(lifted_id.(:x)) + end end end - end - # m >>= return = m - describe "right identity" do - context "when i have nothing" do - it do - expect(Nothing.bind(&lifted_id)).to eq(Nothing) + # m >>= return = m + describe "right identity" do + context "when i have nothing" do + it do + expect(Nothing.public_send(m, &lifted_id)).to eq(Nothing) + end end - end - context "when i have just :x" do - it do - expect(Just(:x).bind(&lifted_id)).to eq(Just(:x)) + context "when i have just :x" do + it do + expect(Just(:x).public_send(m, &lifted_id)).to eq(Just(:x)) + end end end - end - # (m >>= f) >>= g = m >>= (\x -> f x >>= g) - describe "associativity" do - context "when i have nothing" do - it do - lhs = Nothing.bind(&f).bind(&g) - rhs = Nothing.bind { |x| f.(x).bind(&g) } - expect(lhs).to eq(rhs) + # (m >>= f) >>= g = m >>= (\x -> f x >>= g) + describe "associativity" do + context "when i have nothing" do + it do + lhs = Nothing.public_send(m, &f).public_send(m, &g) + rhs = Nothing.bind { |x| f.(x).public_send(m, &g) } + expect(lhs).to eq(rhs) + end end - end - context "when i have just :x" do - it do - lhs = Just(:x).bind(&f).bind(&g) - rhs = Just(:x).bind { |x| f.(x).bind(&g) } - expect(lhs).to eq(rhs) + context "when i have just :x" do + it do + lhs = Just(:x).public_send(m, &f).public_send(m, &g) + rhs = Just(:x).bind { |x| f.(x).public_send(m, &g) } + expect(lhs).to eq(rhs) + end end end end end