edges 0.9.0.1 → 0.9.0.2
raw patch · 4 files changed
+51/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- edges.cabal +1/−1
- library/Edges/Functions.hs +7/−2
- library/Edges/Functions/Folds.hs +3/−0
- library/Edges/Prelude.hs +40/−0
edges.cabal view
@@ -1,5 +1,5 @@ name: edges-version: 0.9.0.1+version: 0.9.0.2 category: Graphs synopsis: Tools for efficient immutable graphs description: A set of tools for constructing immutable graphs which are both memory and performance-efficient.
library/Edges/Functions.hs view
@@ -69,5 +69,10 @@ nodeCountsUnboxedVector (NodeCounts pa) = PrimArray.toUnboxedVector pa unindexNodeCounts :: (Eq entity, Hashable entity) => (Int -> Maybe entity) -> NodeCounts entity -> HashMap entity Int-unindexNodeCounts lookup (NodeCounts pa) =- Unfold.fold (Foldl.hashMapByKeyLookup lookup) (Unfold.intsInRange 0 (pred (sizeofPrimArray pa)))+unindexNodeCounts lookup (NodeCounts pa) = let+ unfold = do+ index <- Unfold.intsInRange 0 (pred (sizeofPrimArray pa))+ return $ do+ entity <- lookup index+ return (entity, fromIntegral (indexPrimArray pa index))+ in Unfold.fold (Foldl.hashMapByMapMaybe id) unfold
library/Edges/Functions/Folds.hs view
@@ -7,6 +7,9 @@ import qualified Data.HashMap.Strict as HashMap +hashMapByMapMaybe :: (Eq b, Hashable b) => (a -> Maybe (b, c)) -> Fold a (HashMap b c)+hashMapByMapMaybe mapMaybe = lmap mapMaybe (handles _Just hashMap)+ hashMapByKeyLookup :: (Eq b, Hashable b) => (a -> Maybe b) -> Fold a (HashMap b a) hashMapByKeyLookup lookup = Fold (flip updateMap) init extract where updateMap a = case lookup a of
library/Edges/Prelude.hs view
@@ -6,6 +6,16 @@ forMInAscendingRange_, forMInDescendingRange_, (.),+ showText,+ -- * Optics+ Lens,+ Lens',+ Prism,+ Prism',+ lens,+ prism,+ _Left,+ _Just, ) where @@ -156,3 +166,33 @@ forMInDescendingRange_ :: Applicative m => Int -> Int -> (Int -> m a) -> m () forMInDescendingRange_ !startN !endN f = ($ pred startN) $ fix $ \loop !n -> if n >= endN then f n *> loop (pred n) else pure ()++showText = fromString . show+++-- * Optics+-------------------------++type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t++type Lens' s a = Lens s s a a++type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)++type Prism' s a = Prism s s a a++{-# INLINE lens #-}+lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b+lens sa sbt afb s = sbt s <$> afb (sa s)++{-# INLINE prism #-}+prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b+prism bt seta = dimap seta (either pure (fmap bt)) . right'++{-# INLINE _Left #-}+_Left :: Prism' (Either a b) a+_Left = prism Left (either Right (Left . Right))++{-# INLINE _Just #-}+_Just :: Prism' (Maybe a) a+_Just = prism Just (maybe (Left Nothing) Right)