[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] itertools 0.1 - Functional iterators based on coroutines
- From: Adrián Pérez de Castro <aperez@...>
- Date: Mon, 12 Sep 2016 13:24:41 +0200
Hello all,
Repository: https://github.com/aperezdc/lua-itertools
Documentation: https://aperezdc.github.io/lua-itertools
LuaRocks: luarocks install itertools
The lua-itertools module provides a collection of functional utilities to use
with coroutine-based iterators. One of the main goals is to provide composable
functions which work well together. Parts of the API are loosely based on some
of the Python builtins (e.g. map, filter), and the itertools [1] module.
So far the module includes functionality that I have needed myself. I am open
to add additional functions — even if it's just a suggestion, contributions
are appreciated :-)
Small usage example (taken from the README):
-- Create an infinite iterator which produces numbers starting at 100
local iterable = itertools.count(100)
-- Filter (select) the numbers which are divisible by three.
iterable = itertools.filter(function (x) return x % 3 == 0 end, iterable)
-- Pick only 10 of the numbers.
iterable = itertools.islice(iterable, 1, 10)
-- Calculate the square of each number
iterable = itertools.map(function (x) return x * x end, iterable)
-- Print them using a for-loop.
for item in iterable do print(item) end
Cheers,
--
☛ Adrián
[1] https://docs.python.org/3.5/library/itertools.html
Attachment:
signature.asc
Description: signature