Skip to content

Commit

Permalink
Versions: mapWithVersion
Browse files Browse the repository at this point in the history
ouroboros-consensus will use `Versions` which contain only hot peer
protocols (without warm protocols).  To preserve this interface,
we can  use `mapWithVersions` to add warm peer protocols.  This will be
only useful for warm peer applications which do not need to consult
version data, otherwise we will need to push warm peer protocols down to
consensus.
  • Loading branch information
coot committed Jul 10, 2020
1 parent bf01bb8 commit 6df6ec0
Showing 1 changed file with 17 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@ module Ouroboros.Network.Protocol.Handshake.Version
, simpleSingletonVersions
, foldMapVersions
, combineVersions
, mapWithVersion
) where

import Data.Foldable (toList)
Expand Down Expand Up @@ -70,6 +71,22 @@ instance Functor (Versions vNum extra) where
where
fmapSigma (Sigma t (Version (Application app) extra)) = Sigma t (Version (Application $ \x y -> f (app x y)) extra)


mapWithVersion
:: forall vNum extra a b.
(vNum -> a -> b)
-> Versions vNum extra a
-> Versions vNum extra b
mapWithVersion f (Versions vs) = Versions $ Map.mapWithKey g vs
where
g :: vNum -> Sigma (Version extra a) -> Sigma (Version extra b)
g vNum (Sigma vData (Version (Application app) extra)) =
Sigma vData
(Version
(Application $ \vData' vData'' -> f vNum (app vData' vData''))
extra)


data Sigma f where
Sigma :: !t -> !(f t) -> Sigma f

Expand Down

0 comments on commit 6df6ec0

Please sign in to comment.