File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
clash-protocols-base/src/Protocols Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,19 @@ repeatC ::
207207repeatC (Circuit f) =
208208 Circuit (C. unzip . C. map f . uncurry C. zip )
209209
210+ {- | Copy a circuit /n/ times, providing access to the index of each replica.
211+ If looking for a circuit that turns a single channel into multiple, check out
212+ 'Protocols.Df.fanout'.
213+ -}
214+ repeatWithIndexC
215+ :: forall n a b . (C. KnownNat n ) =>
216+ (C. Index n -> Circuit a b ) ->
217+ Circuit (C. Vec n a ) (C. Vec n b )
218+ repeatWithIndexC f =
219+ Circuit (C. unzip . C. zipWith g C. indicesI . uncurry C. zip )
220+ where
221+ g i = case f i of Circuit f' -> f'
222+
210223{- | Combine two separate circuits into one. If you are looking to combine
211224multiple streams into a single stream, checkout 'Protocols.Df.fanin'.
212225-}
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ module Protocols (
3030 -- * Basic circuits
3131 idC ,
3232 repeatC ,
33+ repeatWithIndexC ,
3334 prod2C ,
3435
3536 -- * Simulation
You can’t perform that action at this time.
0 commit comments