Sha256: 35686610212c19c2ca213d1aef433b29d0ead7cf32fc35d51e9da3e54eb76ae2

Contents?: true

Size: 630 Bytes

Versions: 2

Compression:

Stored size: 630 Bytes

Contents

module Rupture
  class LazySeq < Seq
    def initialize(block = nil)
      @block = block
    end

    def seq
      return @seq unless @block
      @seq   = @block.call.seq
      @block = nil
      @seq
    end
  end
end

module Enumerable
  def seq
    F.lazy_seq do
      callcc do |external|
        each do |item|
          external = callcc do |internal|
            rest = F.lazy_seq do
              callcc do |external|
                internal.call(external)
              end
            end
            external.call(F.cons(item, rest))
          end
        end
        external.call(nil)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rupture-0.2.1 lib/rupture/lazy_seq.rb
rupture-0.2.0 lib/rupture/lazy_seq.rb