File: io.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'immutable/list'

# Monkey-patches to Ruby's built-in `IO` class.
# @see http://www.ruby-doc.org/core/IO.html
class IO
  # Return a lazy list of "records" read from this IO stream.
  # "Records" are delimited by `$/`, the global input record separator string.
  # By default, it is `"\n"`, a newline.
  #
  # @return [List]
  def to_list(sep = $/) # global input record separator
    Immutable::LazyList.new do
      line = gets(sep)
      if line
        Immutable::Cons.new(line, to_list)
      else
        EmptyList
      end
    end
  end
end