Sha256: ed278b3a3de1d52310eacccb76b6f0bc3afac5ab24c489e85ef155507995d627

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 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

1 entries across 1 versions & 1 rubygems

Version Path
option-1.2.1 spec/acceptance_spec.rb