Open kjh618 opened 2 weeks ago
Actually, we can represent the interface version of flip
which just flips a tuple interface as follows:
(i, j).comb(|(i1, i2)| (i2, i1))
Thus, given a module m: impl FnOnce(I1, I2) -> (O1, O2)
, we can represent flip(m): impl FnOnce(I2, I1) -> (O2, O1)
using interface combinators like this:
(i2, i1)
.comb(|(i2, i1)| (i1, i2)) // flip
.comb(|(i1, i2)| m(i1, i2)) // m
.comb(|(o1, o2)| (o2, o1)) // flip
It is conceptually the same as flip ∘ m ∘ flip
, as you mentioned.
So, you can just think of flip
as a helper module combinator which wraps the above sequence of comb
s.
(From the discussions on the Oct. 14 class) Would it be better to change the module combinator
flip
to an interface combinator that just flips a tuple interface? Then with a function composition operator ∘ (is thiscomb
?), we can doflip ∘ m ∘ flip
to flip both the ingress and the egress interface.