From 42ec7286b2d36a9ba22925f816a17cb1cc2aa5ce Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 30 Oct 2021 11:32:16 +0800 Subject: + Penlight --- .../Penlight/docs/libraries/pl.input.html | 336 +++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 Data/Libraries/Penlight/docs/libraries/pl.input.html (limited to 'Data/Libraries/Penlight/docs/libraries/pl.input.html') diff --git a/Data/Libraries/Penlight/docs/libraries/pl.input.html b/Data/Libraries/Penlight/docs/libraries/pl.input.html new file mode 100644 index 0000000..d0086fd --- /dev/null +++ b/Data/Libraries/Penlight/docs/libraries/pl.input.html @@ -0,0 +1,336 @@ + + + + + Penlight Documentation + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module pl.input

+

Iterators for extracting words or numbers from an input source.

+

+ + + +

+require 'pl'
+local total,n = seq.sum(input.numbers())
+print('average',total/n)
+
+ +

source is defined as a string or a file-like object (i.e. has a read() method which returns the next line)

+ +

See here

+ +

Dependencies: pl.utils

+

+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + +
alltokens (getter, pattern[, fn])create an iterator over all tokens.
create_getter (f)create a function which grabs the next value from a source.
numbers (f)generate a sequence of numbers from a source.
words (f)generate a sequence of words from a source.
fields (ids, delim, f, opts)parse an input source into fields.
+ +
+
+ + +

Functions

+ +
+
+ + alltokens (getter, pattern[, fn]) +
+
+ create an iterator over all tokens. + based on allwords from PiL, 7.1 + + +

Parameters:

+
    +
  • getter + func + any function that returns a line of text +
  • +
  • pattern + string + + + +
  • +
  • fn + string + Optionally can pass a function to process each token as it's found. + (optional) +
  • +
+ +

Returns:

+
    + + an iterator +
+ + + + +
+
+ + create_getter (f) +
+
+ create a function which grabs the next value from a source. If the source is a string, then the getter + will return the string and thereafter return nil. If not specified then the source is assumed to be stdin. + + +

Parameters:

+
    +
  • f + a string or a file-like object (i.e. has a read() method which returns the next line) +
  • +
+ +

Returns:

+
    + + a getter function +
+ + + + +
+
+ + numbers (f) +
+
+ generate a sequence of numbers from a source. + + +

Parameters:

+
    +
  • f + A source +
  • +
+ +

Returns:

+
    + + An iterator +
+ + + + +
+
+ + words (f) +
+
+ generate a sequence of words from a source. + + +

Parameters:

+
    +
  • f + A source +
  • +
+ +

Returns:

+
    + + An iterator +
+ + + + +
+
+ + fields (ids, delim, f, opts) +
+
+ parse an input source into fields. + By default, will fail if it cannot convert a field to a number. + + +

Parameters:

+
    +
  • ids + a list of field indices, or a maximum field index +
  • +
  • delim + string + delimiter to parse fields (default space) +
  • +
  • f + a source @see create_getter +
  • +
  • opts + tab + option table, {no_fail=true} +
  • +
+ +

Returns:

+
    + + an iterator with the field values +
+ + + +

Usage:

+
    +
    for x,y in fields {2,3} do print(x,y) end -- 2nd and 3rd fields from stdin
    +
+ +
+
+ + +
+
+
+generated by LDoc 1.4.6 +
+
+ + -- cgit v1.1-26-g67d0