Skip to content

Commit

Permalink
Merge pull request #79 from fumieval/vector-0.12.2.0
Browse files Browse the repository at this point in the history
Use combinators from vector-0.12.2.0
  • Loading branch information
phadej authored Feb 6, 2021
2 parents 9b863d7 + e760e43 commit 053c1c1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
35 changes: 1 addition & 34 deletions witherable/src/Witherable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ import qualified Data.Sequence as S
import qualified Data.Set as Set
import qualified Data.Traversable as T
import qualified Data.Vector as V
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Fusion.Bundle as V.B
import qualified Data.Vector.Fusion.Bundle.Size as V.BS
import qualified Data.Vector.Fusion.Bundle.Monadic as V.MB
import qualified Data.Vector.Fusion.Stream.Monadic as V.MS
import qualified GHC.Generics as Generics
import qualified Prelude

Expand Down Expand Up @@ -252,37 +247,9 @@ instance Witherable V.Vector where
wither f = fmap V.fromList . wither f . V.toList
{-# INLINABLE wither #-}

witherM f = unstreamM . bundleWitherM f . V.B.lift . VG.stream
witherM = V.mapMaybeM
{-# INLINE witherM #-}

-- This is not yet in any released Vector
unstreamM :: Monad m => V.MB.Bundle m v a -> m (V.Vector a)
unstreamM s = do
xs <- V.MB.toList s
return $ VG.unstream $ V.B.unsafeFromList (V.MB.size s) xs
{-# INLINE unstreamM #-}

bundleWitherM :: Monad m => (a -> m (Maybe b)) -> V.MB.Bundle m v a -> V.MB.Bundle m v b
bundleWitherM g V.MB.Bundle {V.MB.sElems = s, V.MB.sSize = n} =
V.MB.fromStream (streamWitherM g s) (V.BS.toMax n)
{-# INLINE bundleWitherM #-}

streamWitherM :: Monad m => (a -> m (Maybe b)) -> V.MS.Stream m a -> V.MS.Stream m b
streamWitherM g (V.MS.Stream step t) = V.MS.Stream step' t
where
{-# INLINE step' #-}
step' s = do
r <- step s
case r of
V.MS.Yield x s' -> do
b <- g x
case b of
Just y -> return $ V.MS.Yield y s'
Nothing -> return $ V.MS.Skip s'
V.MS.Skip s' -> return $ V.MS.Skip s'
V.MS.Done -> return $ V.MS.Done
{-# INLINE streamWitherM #-}

instance Filterable S.Seq where
mapMaybe f = S.fromList . mapMaybe f . F.toList
{-# INLINABLE mapMaybe #-}
Expand Down
2 changes: 1 addition & 1 deletion witherable/witherable.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library
hashable >=1.2.7.0 && <1.4,
transformers >=0.5.2.0 && <0.6,
unordered-containers >=0.2.12.0 && <0.3,
vector >=0.12 && <0.13,
vector >=0.12.2.0 && <0.13,
indexed-traversable >=0.1.1 && <0.2,
indexed-traversable-instances >=0.1 && <0.2
hs-source-dirs: src
Expand Down

0 comments on commit 053c1c1

Please sign in to comment.