Add each-line combinator
parent
7b392c88e6
commit
1a3f148c2c
|
@ -253,6 +253,10 @@ HELP: lines
|
|||
{ $values { "stream" "an input stream" } { "seq" "a sequence of strings" } }
|
||||
{ $description "Reads lines of text until the stream is exhausted, collecting them in a sequence of strings." } ;
|
||||
|
||||
HELP: each-line
|
||||
{ $values { "quot" { $quotation "( str -- )" } } }
|
||||
{ $description "Calls the quotatin with successive lines of text, until the current " { $link input-stream } " is exhausted." } ;
|
||||
|
||||
HELP: contents
|
||||
{ $values { "stream" "an input stream" } { "str" string } }
|
||||
{ $description "Reads the entire contents of a stream into a string." }
|
||||
|
@ -364,6 +368,8 @@ ARTICLE: "stream-utils" "Stream utilities"
|
|||
$nl
|
||||
"First, a simple composition of " { $link stream-write } " and " { $link stream-nl } ":"
|
||||
{ $subsection stream-print }
|
||||
"Processing lines one by one:"
|
||||
{ $subsection each-line }
|
||||
"Sluring an entire stream into memory all at once:"
|
||||
{ $subsection lines }
|
||||
{ $subsection contents }
|
||||
|
|
|
@ -99,6 +99,9 @@ SYMBOL: error-stream
|
|||
: lines ( stream -- seq )
|
||||
[ [ readln dup ] [ ] [ drop ] produce ] with-input-stream ;
|
||||
|
||||
: each-line ( quot -- )
|
||||
[ [ readln dup ] ] dip [ drop ] while ; inline
|
||||
|
||||
: contents ( stream -- str )
|
||||
[
|
||||
[ 65536 read dup ] [ ] [ drop ] produce concat f like
|
||||
|
|
Loading…
Reference in New Issue