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