Sha256: b2477c478268f8ae53e9bf178f503327143c9daaf9efc48cf976e0661b4dde82

Contents?: true

Size: 609 Bytes

Versions: 7

Compression:

Stored size: 609 Bytes

Contents

require 'test_helper'

class FutureTest < MiniTest::Unit::TestCase
  def test_immediate_value
    assert_equal 30, Future(30).await
  end

  def test_simple_future_executes_in_parallel
    str = ""
    Future { sleep 0.1; str << "bar" }.tap {
      str << "foo"
    }.await
    assert_equal "foobar", str
  end

  def test_bind
    f = Future(30) >-> n {
      Future { n.call * 2 }
    } >-> n {
      Future { n.call * 2 } >-> m {
        Future(m.call + 2)
      }
    }
    assert_equal 122, f.await
  end

  def test_fmap
    f = Future(30).fmap { |x| x.call * 2 }
    assert_equal 60, f.await
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kleisli-0.2.0 test/kleisli/future_test.rb
kleisli-0.1.0 test/kleisli/future_test.rb
kleisli-0.0.6 test/kleisli/future_test.rb
kleisli-0.0.5 test/kleisli/future_test.rb
kleisli-0.0.3 test/kleisli/future_test.rb
kleisli-0.0.2 test/kleisli/future_test.rb
kleisli-0.0.1 test/kleisli/future_test.rb