lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hello all,

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 = (x) return x * x end, iterable)

  -- Print them using a for-loop.
  for item in iterable do print(item) end


 ☛ Adrián


Attachment: signature.asc
Description: signature