-- Import the module.
local itertools = require "itertools"
-- 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
-
Notifications
You must be signed in to change notification settings - Fork 0
aperezdc/lua-itertools
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Functional iterators for Lua based on coroutines
Resources
Stars
Watchers
Forks
Packages 0
No packages published