on master help sign in
change the signature of fromStrictMaybe and rename it

A pure function is a better building block than the monadic one.

commit233ea77f03b63f217aa810b37f36f73a8c413764 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 17 Feb 2020, 19:39 (7 years ago) parent3cde3c7
2 files changed+8−8
src/Streamly/Internal/Data/Fold.hs+3−3 src/Streamly/Internal/Data/Strict.hs+5−5
src/Streamly/Internal/Data/Fold.hs+3−3
@@ -348,7 +348,7 @@ transform (Pipe pstep1 pstep2 pinitial) (Fold fstep finitial fextract) =
348348-- from the 'Foldable', the result is 'None' for empty containers.
349349{-# INLINABLE _Fold1 #-}
350350_Fold1 :: Monad m => (a -> a -> a) -> Fold m a (Maybe a)
351−_Fold1 step = Fold step_ (return Nothing') fromStrictMaybe
351+_Fold1 step = Fold step_ (return Nothing') (return . toMaybe)
352352 where
353353 step_ mx a = return $ Just' $
354354 case mx of
@@ -692,7 +692,7 @@ head = _Fold1 const
692692-- @since 0.7.0
693693{-# INLINABLE find #-}
694694find :: Monad m => (a -> Bool) -> Fold m a (Maybe a)
695−find predicate = Fold step (return Nothing') fromStrictMaybe
695+find predicate = Fold step (return Nothing') (return . toMaybe)
696696 where
697697 step x a = return $
698698 case x of
@@ -707,7 +707,7 @@ find predicate = Fold step (return Nothing') fromStrictMaybe
707707-- @since 0.7.0
708708{-# INLINABLE lookup #-}
709709lookup :: (Eq a, Monad m) => a -> Fold m (a,b) (Maybe b)
710−lookup a0 = Fold step (return Nothing') fromStrictMaybe
710+lookup a0 = Fold step (return Nothing') (return . toMaybe)
711711 where
712712 step x (a,b) = return $
713713 case x of
src/Streamly/Internal/Data/Strict.hs+5−5
@@ -23,7 +23,7 @@ module Streamly.Internal.Data.Strict
2323 , Tuple3' (..)
2424 , Tuple4' (..)
2525 , Maybe' (..)
26− , fromStrictMaybe
26+ , toMaybe
2727 , Either' (..)
2828 )
2929where
@@ -46,10 +46,10 @@ data Maybe' a = Just' !a | Nothing' deriving Show
4646-- XXX perhaps we can use a type class having fromStrict/toStrict operations.
4747--
4848-- | Convert strict Maybe' to lazy Maybe
49−{-# INLINABLE fromStrictMaybe #-}
50−fromStrictMaybe :: Monad m => Maybe' a -> m (Maybe a)
51−fromStrictMaybe Nothing' = return $ Nothing
52−fromStrictMaybe (Just' a) = return $ Just a
49+{-# INLINABLE toMaybe #-}
50+toMaybe :: Maybe' a -> Maybe a
51+toMaybe Nothing' = Nothing
52+toMaybe (Just' a) = Just a
5353
5454-------------------------------------------------------------------------------
5555-- Either