- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum.lua
More file actions
Latest commit
39 lines (33 loc) · 1.05 KB
/
Copy pathenum.lua
File metadata and controls
39 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
localEnum= {}
Enum.__index=Enum
functionEnum.count(enumerable)
Enumerable.is_defined_for(enumerable)
localreducer=function(x, acc)
return"cont", acc+1
end
localresult, count=enumerable:reduce(reducer, "cont", 0)
returncount
end
functionEnum.foldl(enumerable, acc, fun)
Enumerable.is_defined_for(enumerable)
localreducer=function(x, acc)
return"cont", fun(x, acc)
end
localresult, value=enumerable:reduce(reducer, "cont", acc)
print(result, value)
returnvalue
end
localinto=function(enumerable, initial, fun, callback)
localvalue=Enum.foldl(enumerable, initial, callback)
returnfun(value, "done")
end
functionEnum.into(enumerable, collectable, fun)
Enumerable.is_defined_for(enumerable)
Collectable.is_defined_for(collectable)
localinitial, collectable_fun=collectable:into()
localcallback=function(x, acc)
returncollectable_fun(acc, "cont", fun(x))
end
returninto(enumerable, initial, collectable_fun, callback)
end
returnEnum