diff --git a/.travis.yml b/.travis.yml index d15e621..ec6516a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,20 +21,22 @@ before_install: - pip install --user hererocks - hererocks env --$LUA -rlatest # Use latest LuaRocks, install into 'env' directory. - source env/bin/activate # Add directory with all installed binaries to PATH. + - luarocks install luacov + - luarocks install luacov-coveralls --server=https://rocks.moonscript.org/dev # - luarocks install busted # - pip install cpp-coveralls # - luarocks install Lua-cURL --server=https://rocks.moonscript.org/dev - # - luarocks install luacov-coveralls --server=https://rocks.moonscript.org/dev # - luarocks install lunitx install: - luarocks make script: - - lua test.lua + - lua -lluacov test.lua # - lunit.sh test.lua -#after_success: +after_success: + - luacov-coveralls -v -i iter.lua -i test.impl.lua # - coveralls -b .. -r .. --dump c.report.json # - luacov-coveralls -j c.report.json -v diff --git a/README.md b/README.md index 0678d5f..6e16537 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Lua Iteration Library ======================== [![Build Status](https://travis-ci.org/starwing/luaiter.svg?branch=master)](https://travis-ci.org/starwing/luaiter) +[![Coverage Status](https://coveralls.io/repos/github/starwing/luaiter/badge.svg?branch=master)](https://coveralls.io/github/starwing/luaiter?branch=master) luaiter is a rewritten version of [luafun][1]: a high-performance functional programming library for Lua designed with LuaJIT's trace diff --git a/iter.lua b/iter.lua index b4593bf..d4a98cd 100644 --- a/iter.lua +++ b/iter.lua @@ -1056,7 +1056,7 @@ end setmetatable(Operator, { __call = function(self, op) - return iter._(assert(self[op], "not such operator")) + return iter._(assert(self[op], "no such operator")) end }) diff --git a/test.impl.lua b/test.impl.lua index 0c6748c..7bf7a01 100644 --- a/test.impl.lua +++ b/test.impl.lua @@ -142,6 +142,10 @@ for _, a in iter(1, 2, 3, 4, 5, 6, 7) do print(a) end attempt to iterate a number value --]] +op"--" +--[[ERROR +no such operator +--]] --! each @@ -403,6 +407,24 @@ print(all(_"_1 >= 10, _1 <= 20", take(20, rand(10, 20)))) true --]] +local f, r = split(5, range(10)) +f:each(print) +print '---' +r:each(print) +--[[OUTPUT +1 +2 +3 +4 +5 +--- +6 +7 +8 +9 +10 +--]] + --iter.array = array --iter.resolve = resolve @@ -644,6 +666,14 @@ iter {1,2,2,3,3,4,5} :groupby(_"_2, _2"):map(_G.unpack or table.unpack) 5 --]] +iter {1,2,2,3,3,4,5} :group(3):map(_G.unpack or table.unpack) +:each(print) +--[[OUTPUT +1,1,2,2,3,2 +4,3,5,3,6,4 +7,5 +--]] + array {1,2,2,3,3,4,5} :packgroupby():flatmap(array):map(_G.unpack or table.unpack) :each(print) --[[OUTPUT @@ -675,6 +705,14 @@ c,three d,nil --]] +zip(array{"a", "b", "c", "d"}, iter{"one", "two", "three"}):each(print) +--[[OUTPUT +a,1,one +b,2,two +c,3,three +d,nil +--]] + zipall(array{"a", "b", "c", "d"}, array{"one", "two", "three"}):each(print) --[[OUTPUT a,one @@ -819,6 +857,35 @@ filter(_"_1 % 3 == 0", range(10)):each(print) 9 --]] +filterout(_"_1 % 3 == 0", range(10)):each(print) +--[[OUTPUT +1 +2 +4 +5 +7 +8 +10 +--]] + +local f1,r1 = partition(_"_1 % 3 == 0", range(10)) +f1:each(print) +print'---' +r1:each(print) +--[[OUTPUT +3 +6 +9 +--- +1 +2 +4 +5 +7 +8 +10 +--]] + filter(_"_1 % 3 == 0", range(0)):each(print) --[[OUTPUT --]] @@ -880,8 +947,6 @@ Emma --! reducing -eq(_.self(range(10)).reduce(op.add)(), 55) - eq(range(10):map(-_1):reduce(_1+_2), -55) eq(foldl(_1 + _2, nil, range(5)), 15) eq(foldl(_1 + _2, 0, range(5)), 15) @@ -924,6 +989,15 @@ eq(any(_1, {}), false) --! operators +eq(_.self(range(10)).reduce(op.add)(), 55) +eq(_(_1.range)(10)(_G):reduce(op.add), 55) +_(_3)(_2, _1.._2, _.dots)("world", "hello", print, "a", "b", "c") +print(_.andor(_.le(_1, _2), _3, _4)(1, 2, "foo", "bar")) +--[[OUTPUT +hello,worldhello,a,b,c +foo +--]] + eq(op, operator) -- an alias local comparators = { 'le', 'lt', 'eq', 'ne', 'ge', 'gt' }