7 people like it.

Abstract Console.ReadLine as an infinite sequence

Abstracts console input as an infinite sequence of lines of text

1: 
2: 
3: 
4: 
5: 
6: 
open System

let console = Seq.initInfinite (fun _ -> Console.ReadLine())
console |> Seq.iter (fun line ->
  printfn "You said %s" line
)
namespace System
val console : seq<string>

Full name: Script.console
module Seq

from Microsoft.FSharp.Collections
val initInfinite : initializer:(int -> 'T) -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.initInfinite
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
Console.ReadLine() : string
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
val line : string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/2I
Posted:13 years ago
Author:fholm
Tags: console , seq