Sha256: 4f448dfa9f9980aca612014c4cbdd5288c6ea377261009e7920721570a2df31c

Contents?: true

Size: 738 Bytes

Versions: 4

Compression:

Stored size: 738 Bytes

Contents

require "spec_helper"

some = Some("test")
upcase = lambda { |v| Some(v.upcase) }
empty  = lambda { |v| None }

describe "Option" do

  describe "when applying the 3 monadic axioms" do

    describe "left identity" do

      it "obeys (return x) >>= f == f x" do
        some.flat_map(&upcase).must_equal(upcase.call(some.get))
      end
    end

    describe "right identity" do

      it "obeys m >>= return == m" do
        some.flat_map { |v| Some(v) }.must_equal(some)
      end
    end

    describe "associative composition" do

      it "obeys (m >>= f) >>= g == m >>= (\\x -> f x >>= g)" do
        some.flat_map(&upcase).flat_map(&empty).
          must_equal(upcase.call(some.get).flat_map(&empty))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
camertron-option-1.0.0 spec/acceptance_spec.rb
option-1.2.0 spec/acceptance_spec.rb
option-1.1.0 spec/acceptance_spec.rb
option-1.0.1 spec/acceptance_spec.rb