We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Chain
1 parent e858645 commit 4bcabfcCopy full SHA for 4bcabfc
src/rewriters.jl
@@ -60,8 +60,8 @@ end
60
61
If(f, x) = IfElse(f, x, Empty())
62
63
-struct Chain
64
- rws
+struct Chain{Cs}
+ rws::Cs
65
stop_on_match::Bool
66
end
67
Chain(rws) = Chain(rws, false)
@@ -78,8 +78,24 @@ function (rw::Chain)(x)
78
79
80
return x
81
+end
82
83
+@generated function (rw::Chain{<:NTuple{N, Any}})(x) where {N}
84
+ quote
85
+ Base.@nexprs $N i -> begin
86
+ f = rw.rws[i]
87
+ y = f(x)
88
+ if rw.stop_on_match && y !== nothing && !isequal(x, y)
89
+ return y
90
+ end
91
+ if y !== nothing
92
+ x = y
93
94
95
+ return x
96
97
98
+
99
instrument(c::Chain, f) = Chain(map(x->instrument(x,f), c.rws))
100
101
struct RestartedChain{Cs}
0 commit comments