diff options
author | chai <chaifix@163.com> | 2021-10-26 11:32:46 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-26 11:32:46 +0800 |
commit | 0549b1e5a8a3132005e275d6026db8003cb067d2 (patch) | |
tree | f0d7751ec32ecf5c4d23997fa0ffd3450a5a755a /Data/DefaultContent/Libraries/luafun/tests/transformations.lua | |
parent | 32345800737b668011a87328cd3dcce59ec2934c (diff) |
*rename folder
Diffstat (limited to 'Data/DefaultContent/Libraries/luafun/tests/transformations.lua')
-rw-r--r-- | Data/DefaultContent/Libraries/luafun/tests/transformations.lua | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/Data/DefaultContent/Libraries/luafun/tests/transformations.lua b/Data/DefaultContent/Libraries/luafun/tests/transformations.lua new file mode 100644 index 0000000..b4fddab --- /dev/null +++ b/Data/DefaultContent/Libraries/luafun/tests/transformations.lua @@ -0,0 +1,107 @@ +-------------------------------------------------------------------------------- +-- map +-------------------------------------------------------------------------------- + +fun = function(...) return 'map', ... end + +dump(map(fun, range(0))) +--[[test +--test]] + + +dump(map(fun, range(4))) +--[[test +map 1 +map 2 +map 3 +map 4 +--test]] + +dump(map(fun, enumerate({"a", "b", "c", "d", "e"}))) +--[[test +map 1 a +map 2 b +map 3 c +map 4 d +map 5 e +--test]] + +dump(map(function(x) return 2 * x end, range(4))) +--[[test +2 +4 +6 +8 +--test]] + +fun = nil +--[[test +--test]] + +-------------------------------------------------------------------------------- +-- enumerate +-------------------------------------------------------------------------------- + +dump(enumerate({"a", "b", "c", "d", "e"})) +--[[test +1 a +2 b +3 c +4 d +5 e +--test]] + +dump(enumerate(enumerate(enumerate({"a", "b", "c", "d", "e"})))) +--[[test +1 1 1 a +2 2 2 b +3 3 3 c +4 4 4 d +5 5 5 e +--test]] + +dump(enumerate(zip({"one", "two", "three", "four", "five"}, + {"a", "b", "c", "d", "e"}))) +--[[test +1 one a +2 two b +3 three c +4 four d +5 five e +--test]] + +-------------------------------------------------------------------------------- +-- intersperse +-------------------------------------------------------------------------------- + +dump(intersperse("x", {})) + +dump(intersperse("x", {"a", "b", "c", "d", "e"})) +--[[test +a +x +b +x +c +x +d +x +e +x +--test]] + +dump(intersperse("x", {"a", "b", "c", "d", "e", "f"})) +--[[test +a +x +b +x +c +x +d +x +e +x +f +x +--test]] |