Sha256: 042ab9d101c78c7dacc6a40c7a4e311487eb18a39d595cdbee741150bfdfe459

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require_relative '../spec_helper'

describe 'Either' do
  it 'can be used in filter and map' do
    eithers = sequence(left('error'), right(3))
    expect(eithers.filter(is_left?).map(get_left)).to eq(sequence('error'))
    expect(eithers.filter(is_right?).map(get_right)).to eq(sequence(3))
  end

  it 'should support map' do
    expect(right(3).map(add(2))).to eq(right(5))
    expect(right(3).map { |a| a+2 }).to eq(right(5))
    expect(left(3).map_lr(add(2), nil)).to eq(5)
    expect(right(3).map_lr(nil, add(2))).to eq(5)
  end

  it 'should support map_left' do
    expect(right(3).map_left(add(2))).to eq(right(3))
    expect(right(3).map_left { |a| a+2 }).to eq(right(3))
    expect(left(3).map_left(add(2))).to eq(left(5))
    expect(left(3).map_left { |a| a+2 }).to eq(left(5))
  end

  it 'should raise exception if you try to use both lambda and block' do
    expect { right(1).map(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
    expect { right(1).map_left(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
    expect { left(1).map_left(add(2)) { |a| a+2 } }.to raise_error(RuntimeError)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
totally_lazy-0.1.28 spec/totally_lazy/either_spec.rb