aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/codes_from_doc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/outputs/codes_from_doc.lua')
-rw-r--r--spec/outputs/codes_from_doc.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua
index 177c33d..3ee20bb 100644
--- a/spec/outputs/codes_from_doc.lua
+++ b/spec/outputs/codes_from_doc.lua
@@ -694,6 +694,7 @@ local some_string = "Here is a string\n that has a line break in it."
694print("I am " .. tostring(math.random() * 100) .. "% sure.") 694print("I am " .. tostring(math.random() * 100) .. "% sure.")
695local integer = 1000000 695local integer = 1000000
696local hex = 0xEFBBBF 696local hex = 0xEFBBBF
697local binary = 19
697local my_function 698local my_function
698my_function = function() end 699my_function = function() end
699my_function() 700my_function()
@@ -2228,6 +2229,38 @@ local inventory = {
2228 } 2229 }
2229 } 2230 }
2230} 2231}
2232local map
2233map = function(arr, action)
2234 local _accum_0 = { }
2235 local _len_0 = 1
2236 for _index_0 = 1, #arr do
2237 local item = arr[_index_0]
2238 _accum_0[_len_0] = action(item)
2239 _len_0 = _len_0 + 1
2240 end
2241 return _accum_0
2242end
2243local filter
2244filter = function(arr, cond)
2245 local _accum_0 = { }
2246 local _len_0 = 1
2247 for _index_0 = 1, #arr do
2248 local item = arr[_index_0]
2249 if cond(item) then
2250 _accum_0[_len_0] = item
2251 _len_0 = _len_0 + 1
2252 end
2253 end
2254 return _accum_0
2255end
2256local reduce
2257reduce = function(arr, init, action)
2258 for _index_0 = 1, #arr do
2259 local item = arr[_index_0]
2260 init = action(init, item)
2261 end
2262 return init
2263end
2231print(reduce(filter(map({ 2264print(reduce(filter(map({
2232 1, 2265 1,
2233 2, 2266 2,