Skip to content

Commit

Permalink
Revert "Distribute more generally"
Browse files Browse the repository at this point in the history
This reverts commit 5feea42.
  • Loading branch information
matthewbauer committed Jan 31, 2020
1 parent 04403d3 commit 8064382
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/Reflex/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ module Reflex.Class
, gate
-- ** Combining 'Dynamic's
, distributeDMapOverDynPure
, distributeDMapOverDynPureG
, distributeListOverDyn
, distributeListOverDynWith
, zipDyn
Expand Down Expand Up @@ -1110,21 +1109,12 @@ instance (Reflex t, Monoid a) => Monoid (Dynamic t a) where
-- 'Dynamic' 'DMap'. Its implementation is more efficient than doing the same
-- through the use of multiple uses of 'zipDynWith' or 'Applicative' operators.
distributeDMapOverDynPure :: forall t k. (Reflex t, GCompare k) => DMap k (Dynamic t) -> Dynamic t (DMap k Identity)
distributeDMapOverDynPure = distributeDMapOverDynPureG coerceDynamic

-- | This function converts a 'DMap' whose elements are 'Dynamic's into a
-- 'Dynamic' 'DMap'. Its implementation is more efficient than doing the same
-- through the use of multiple uses of 'zipDynWith' or 'Applicative' operators.
distributeDMapOverDynPureG
:: forall t k q v. (Reflex t, GCompare k)
=> (forall a. q a -> Dynamic t (v a))
-> DMap k q -> Dynamic t (DMap k v)
distributeDMapOverDynPureG nt dm = case DMap.toList dm of
distributeDMapOverDynPure dm = case DMap.toList dm of
[] -> constDyn DMap.empty
[k :=> v] -> DMap.singleton k <$> nt v
[k :=> v] -> fmap (DMap.singleton k . Identity) v
_ ->
let getInitial = DMap.traverseWithKey (\_ -> sample . current . nt) dm
edmPre = mergeG getCompose $ DMap.map (Compose . updated . nt) dm
let getInitial = DMap.traverseWithKey (\_ -> fmap Identity . sample . current) dm
edmPre = merge $ DMap.map updated dm
result = unsafeBuildDynamic getInitial $ flip pushAlways edmPre $ \news -> do
olds <- sample $ current result
return $ DMap.unionWithKey (\_ _ new -> new) olds news
Expand Down

0 comments on commit 8064382

Please sign in to comment.