NAME
NumSeq::Iter - Generate a coderef iterator from a number sequence
specification (e.g. '1,3,5,...,101')
VERSION
This document describes version 0.003 of NumSeq::Iter (from Perl
distribution NumSeq-Iter), released on 2021-07-17.
SYNOPSIS
use NumSeq::Iter qw(numseq_parse numseq_iter);
my $iter = numseq_iter('1,3,5,...,13');
while (my $val = $iter->()) { ... } # 1,3,5,7,9,11,13
my $res = numseq_parse(''); # [400, "Parse fail: Please specify one or more number in number sequence"]
my $res = numseq_parse('1,3,5'); # [200, "OK", {numbers=>[1,2,3], has_ellipsis=>0, type=>'arithmetic', inc=>2}]
my $res = numseq_parse('1,3,9,...'); # [200, "OK", {numbers=>[1,3,9], has_ellipsis=>1, last_number=>undef, type=>'geometric', inc=>3}]
my $res = numseq_parse('1,3,5,...,10'); # [200, "OK", {numbers=>[1,2,3], has_ellipsis=>1, last_number=>10, type=>'arithmetic', inc=>2}]
DESCRIPTION
This module provides a simple (coderef) iterator which you can call
repeatedly to get numbers specified in a number sequence specification
(string). When the numbers are exhausted, the coderef will return undef.
No class/object involved.
A number sequence is a comma-separated list of numbers (either integer
like 1, -2 or decimal number like 1.3, -100.70) with at least one
number. It can contain an ellipsis (e.g. '1,2,3,...' or '1, 3, 5, ...,
10').
When the sequence has an ellipsis, there must be at least three numbers
before the ellipsis. There can optionally be another number after the
ellipsis to make the sequence finite; but the last number can also be
Inf, +Inf, or -Inf. Currently only simple arithmetic sequence ('1,3,5')
or simple geometric sequence ('2,6,18') is recognized.
FUNCTIONS
numseq_iter
Usage:
$iter = numseq_iter([ \%opts ], $spec); # coderef
Options:
numseq_parse
my $res = numseq_parse([ \%opts ], $spec); # enveloped response
See "numseq_iter" for list of known options.
HOMEPAGE
Please visit the project's homepage at
.
SOURCE
Source repository is at .
BUGS
Please report any bugs or feature requests on the bugtracker website
When submitting a bug or request, please include a test-file or a patch
to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
IntRange::Iter, Range::Iter
Raku's lazy lists.
AUTHOR
perlancar
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.