-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstudy.nim
76 lines (59 loc) · 1.57 KB
/
study.nim
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
template study(name, body) = discard
template conclusion(_) = discard
conclusion """
there is/are:
only one for loop
many blocks as map
maybe filters
one reducer always
"""
study "map.[reducer]":
Iter |> map(Op).reducer(Default)
DetectedType: # <- means replace with
it <- default(typeof Iter)
it <- Op
Op2
var resultState =
reducerDefault[typeof DetectedType]() |
reducerDefault(arg1, arg2, .._)
block mainLoop:
for it in Iter:
block: # new block introduces with a map [to localize `it`]
let it = Op
if not reducer(resultState, it):
break mainLoop
study "filter.[reducer]":
Iter |> filter(Cond).reducer(Default)
for it in Iter:
if Cond:
_
study "adapter":
template loop(itrbl, code): untyped {.fake.} =
for it {.inject.} in itrbl:
code
iterator cycle(itrbl: Iter; limit: int): Iter {.adapter.} =
var c = 0
while true:
loop itrbl:
yield it
inc c
if c == limit:
break
## we can't have overloads ...
## choose `untyped` if you want to
iterator repeat(itrbl; t: int): Iter {.adapter.} =
for _ in 1..t:
loop itrbl
iterator flatten(itrbl; t: int): Iter {.adapter.} =
for _ in 1..t:
loop itrbl:
for n in it:
yield n
# =========================>>>>>>>>>>>>>>>>>>>>>>>
for _ in 1..t:
for it in itrbl:
block:
let it = it ## skip this and new block if "let it = it
iseq(lastState, it)
## split the adapter to areas [wrapper, reducer]
## add typeCheck thingy