Skip to content

Commit 241c6c1

Browse files
committed
Introduce repeatWithIndexC
1 parent 5b378a1 commit 241c6c1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clash-protocols-base/src/Protocols/Internal.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ repeatC ::
207207
repeatC (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
211224
multiple streams into a single stream, checkout 'Protocols.Df.fanin'.
212225
-}

clash-protocols/src/Protocols.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Protocols (
3030
-- * Basic circuits
3131
idC,
3232
repeatC,
33+
repeatWithIndexC,
3334
prod2C,
3435

3536
-- * Simulation

0 commit comments

Comments
 (0)