spec/applicative_functor_spec.rb in ribimaybe-0.0.12 vs spec/applicative_functor_spec.rb in ribimaybe-0.0.13
- old
+ new
@@ -19,84 +19,86 @@
let(:g) do
->(x){ ->(y) { x } }.(SecureRandom.base64(1000))
end
- # pure id <*> v = v
- describe "identity" do
- context "when i have nothing" do
- it do
- expect(pure(&id).apply(Nothing)).to eq(Nothing)
+ [:apply, :>>].each do |m|
+ # pure id <*> v = v
+ describe "identity" do
+ context "when i have nothing" do
+ it do
+ expect(pure(&id).public_send(m, Nothing)).to eq(Nothing)
+ end
end
- end
- context "when i have just :x" do
- it do
- expect(pure(&id).apply(pure(:x))).to eq(pure(:x))
+ context "when i have just :x" do
+ it do
+ expect(pure(&id).public_send(m, pure(:x))).to eq(pure(:x))
+ end
end
end
- end
- # pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
- describe "composition" do
- context "when i have nothing" do
- it do
- lhs = pure(&dot).apply(pure(&f)).apply(pure(&g)).apply(Nothing)
- rhs = pure(&f).apply(pure(&g).apply(Nothing))
- expect(lhs).to eq(rhs)
+ # pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
+ describe "composition" do
+ context "when i have nothing" do
+ it do
+ lhs = pure(&dot).public_send(m, pure(&f)).public_send(m, pure(&g)).public_send(m, Nothing)
+ rhs = pure(&f).public_send(m, pure(&g).public_send(m, Nothing))
+ expect(lhs).to eq(rhs)
+ end
end
- end
- context "when i have just :x" do
- it do
- lhs = pure(&dot).apply(pure(&f)).apply(pure(&g)).apply(pure(:x))
- rhs = pure(&f).apply(pure(&g).apply(pure(:x)))
- expect(lhs).to eq(rhs)
+ context "when i have just :x" do
+ it do
+ lhs = pure(&dot).public_send(m, pure(&f)).public_send(m, pure(&g)).public_send(m, pure(:x))
+ rhs = pure(&f).public_send(m, pure(&g).public_send(m, pure(:x)))
+ expect(lhs).to eq(rhs)
+ end
end
end
- end
- # pure f <*> pure x = pure (f x)
- describe "homomorphism" do
- context "when i have nothing" do
- it do
- expect(pure(&f).apply(Nothing)).to eq(Nothing)
+ # pure f <*> pure x = pure (f x)
+ describe "homomorphism" do
+ context "when i have nothing" do
+ it do
+ expect(pure(&f).public_send(m, Nothing)).to eq(Nothing)
+ end
end
- end
- context "when i have just :x" do
- it do
- expect(pure(&f).apply(pure(:x))).to eq(pure(f.(:x)))
+ context "when i have just :x" do
+ it do
+ expect(pure(&f).public_send(m, pure(:x))).to eq(pure(f.(:x)))
+ end
end
end
- end
- # u <*> pure y = pure ($ y) <*> u
- describe "interchange" do
- context "when i have nothing" do
- it do
- expect(pure(&f).apply(Nothing)).to eq(pure(&ap.(f)).apply(Nothing))
+ # u <*> pure y = pure ($ y) <*> u
+ describe "interchange" do
+ context "when i have nothing" do
+ it do
+ expect(pure(&f).public_send(m, Nothing)).to eq(pure(&ap.(f)).public_send(m, Nothing))
+ end
end
- end
- context "when i have just :x" do
- it do
- expect(pure(&f).apply(pure(:x))).to eq(pure(&ap.(f)).apply(pure(:x)))
+ context "when i have just :x" do
+ it do
+ expect(pure(&f).public_send(m, pure(:x))).to eq(pure(&ap.(f)).public_send(m, pure(:x)))
+ end
end
end
- end
- # fmap f x = pure f <*> x
- describe "map" do
- context "when i have nothing" do
- it do
- expect(Nothing.map(&f)).to eq(pure(&f).apply(Nothing))
+ # fmap f x = pure f <*> x
+ describe "map" do
+ context "when i have nothing" do
+ it do
+ expect(Nothing.map(&f)).to eq(pure(&f).public_send(m, Nothing))
+ end
end
- end
- context "when i have just :x" do
- it do
- expect(Just(:x).map(&f)).to eq(pure(&f).apply(Just(:x)))
+ context "when i have just :x" do
+ it do
+ expect(Just(:x).map(&f)).to eq(pure(&f).public_send(m, Just(:x)))
+ end
end
end
end
end