packages feed

universum 0.6.1 → 0.7.0

raw patch · 12 files changed

+126/−67 lines, 12 files

Files

CHANGES.md view
@@ -1,10 +1,27 @@+0.7.0+=====++* [#47](https://github.com/serokell/universum/issues/47):+  Reexport `put` and `get` for `MonadState`.+* [#48](https://github.com/serokell/universum/issues/48):+  Export boxed `Vector` type.+* [#49](https://github.com/serokell/universum/issues/49):+  Export `IdentityT` and `runIdentityT`.+* [#51](https://github.com/serokell/universum/issues/51):+  Add `fromRight` and `fromLeft` that behave like `fromMaybe` but for `Either`.+* [#52](https://github.com/serokell/universum/issues/52):+  Add `maybeToMonoid :: Monoid m => Maybe m -> m`.+* Remove `Symbol`-related types for sure.+* Return back seems to be useful function `guardM` removed in `v0.3`.+* Add `notElem` for `NonTrivialContainer`.+ 0.6.1 =====  * Fixed version number bug (it had 4 numbers).  0.6.0.0-=====+=======  * [#62](https://github.com/serokell/universum/issues/62):   Export exceptions-related functions from 'safe-exceptions'.@@ -15,7 +32,7 @@ * Fix an infinite loop in `decodeUtf8` from `Text` to `ByteString.Lazy`.  0.5-=====+===  * Export `MonadTrans` typeclass. * Remove `Symbol`-related exports from `GHC.TypeLits`.
src/Base.hs view
@@ -37,9 +37,9 @@ import           GHC.Num              (Integer, Num (..), subtract) import           GHC.Real             hiding ((%)) import           GHC.Show             (Show (..))-import           GHC.TypeLits         (CmpNat, KnownNat, KnownSymbol, Nat, SomeNat (..),-                                       SomeSymbol (..), Symbol, natVal, someNatVal,-                                       someSymbolVal, symbolVal)+import           GHC.TypeLits         (CmpNat, KnownNat, Nat, SomeNat (..), natVal,+                                       someNatVal)+ import           GHC.Types            (Bool, Char, Coercible, IO, Int, Ordering, Word)  
src/Bool.hs view
@@ -1,15 +1,20 @@ {-# LANGUAGE Safe #-} --- | Convenient commonly used and very helpful functions to work with 'Bool'.+-- | Convenient commonly used and very helpful functions to work with+-- 'Bool' and also with monads.  module Bool-       ( whenM-       , unlessM+       ( bool+       , guard+       , guardM        , ifM-       , bool+       , unless+       , unlessM+       , when+       , whenM        ) where -import           Control.Monad (Monad, unless, when, (>>=))+import           Control.Monad (Monad, MonadPlus, guard, unless, when, (>>=)) import           Data.Bool     (Bool) import           Data.Function (flip) @@ -52,8 +57,19 @@ -- True text ifM :: Monad m => m Bool -> m a -> m a -> m a ifM p x y = p >>= \b -> if b then x else y+{-# INLINE ifM #-} -{-+-- | Monadic version of 'guard'. Occasionally useful.+-- Here some complex but real-life example:+-- @+--   findSomePath :: IO (Maybe FilePath)+--+--   somePath :: MaybeT IO FilePath+--   somePath = do+--       path <- MaybeT findSomePath+--       guardM $ liftIO $ doesDirectoryExist path+--       return path+-- @ guardM :: MonadPlus m => m Bool -> m ()-guardM f = guard =<< f--}+guardM f = f >>= guard+{-# INLINE guardM #-}
src/Containers.hs view
@@ -206,6 +206,9 @@    elem :: Eq (Element t) => Element t -> t -> Bool +  notElem :: Eq (Element t) => Element t -> t -> Bool+  notElem x = not . elem x+   maximum :: Ord (Element t) => t -> Element t   minimum :: Ord (Element t) => t -> Element t @@ -247,6 +250,8 @@   {-# INLINE length #-}   elem = F.elem   {-# INLINE elem #-}+  notElem = F.notElem+  {-# INLINE notElem #-}   maximum = F.maximum   {-# INLINE maximum #-}   minimum = F.minimum@@ -334,6 +339,8 @@   {-# INLINE length #-}   elem = BS.elem   {-# INLINE elem #-}+  notElem = BS.notElem+  {-# INLINE notElem #-}   maximum = BS.maximum   {-# INLINE maximum #-}   minimum = BS.minimum@@ -362,6 +369,8 @@   {-# INLINE length #-}   elem = BSL.elem   {-# INLINE elem #-}+  notElem = BSL.notElem+  {-# INLINE notElem #-}   maximum = BSL.maximum   {-# INLINE maximum #-}   minimum = BSL.minimum
src/Exceptions.hs view
@@ -11,10 +11,12 @@        , note        ) where -import           Control.Applicative    (Applicative (pure))+-- exceptions from safe-exceptions import           Control.Exception.Safe (Exception, MonadCatch, MonadMask (..),                                          MonadThrow, SomeException (..), bracket,                                          bracket_, catch, catchAny, finally, throwM)++import           Control.Applicative    (Applicative (pure)) import           Control.Monad.Except   (MonadError, throwError) import           Data.Maybe             (Maybe, maybe) 
src/List.hs view
@@ -4,27 +4,31 @@ -- | Utility functions to work with lists.  module List-       ( list+       ( module Data.List++       , list        , hashNub        , ordNub-       , sortBy-       , sortOn        , sortWith-       , unzip-       , unzip3 #if ( __GLASGOW_HASKELL__ >= 800 )        , whenNotNull        , whenNotNullM #endif-       , zip-       , zip3        ) where +import           Data.List           (break, cycle, drop, dropWhile, filter, genericDrop,+                                      genericLength, genericReplicate, genericSplitAt,+                                      genericTake, group, inits, intercalate, intersperse,+                                      isPrefixOf, iterate, permutations, repeat,+                                      replicate, reverse, scanl, scanr, sort, sortBy,+                                      sortBy, sortOn, splitAt, subsequences, tails, take,+                                      takeWhile, transpose, unfoldr, unzip, unzip3, zip,+                                      zip3, zipWith)+ import           Data.Eq             (Eq) import           Data.Functor        (fmap) import           Data.Hashable       (Hashable) import           Data.HashSet        as HS-import           Data.List           (sortBy, sortOn, unzip, unzip3, zip, zip3) import           Data.Ord            (Ord) import qualified Data.Set            as Set import           GHC.Exts            (sortWith)
src/Monad.hs view
@@ -32,10 +32,6 @@        , concatMapM        , concatForM -       , guard-       , when-       , unless-        , allM        , anyM        , andM
src/Monad/Either.hs view
@@ -4,6 +4,8 @@  module Monad.Either        ( module Data.Either+       , fromLeft+       , fromRight        , maybeToLeft        , maybeToRight        , leftToMaybe@@ -22,6 +24,27 @@ import           Data.Maybe          (Maybe (..), maybe)  import           Applicative         (pass)+++-- | Extracts value from 'Left' or return given default value.+--+-- >>> fromLeft 0 (Left 3)+-- 3+-- >>> fromLeft 0 (Right 5)+-- 0+fromLeft :: a -> Either a b -> a+fromLeft _ (Left a)  = a+fromLeft a (Right _) = a++-- | Extracts value from 'Right' or return given default value.+--+-- >>> fromRight 0 (Left 3)+-- 0+-- >>> fromRight 0 (Right 5)+-- 5+fromRight :: b -> Either a b -> b+fromRight b (Left _)  = b+fromRight _ (Right b) = b  -- | Maps left part of 'Either' to 'Maybe'. --
src/Monad/Maybe.hs view
@@ -3,7 +3,10 @@ -- | Utility functions to work with 'Data.Maybe' data type as monad.  module Monad.Maybe-       ( whenJust+       ( module Data.Maybe++       , maybeToMonoid+       , whenJust        , whenJustM        , whenNothing        , whenNothing_@@ -11,11 +14,23 @@        , whenNothingM_        ) where +import           Data.Maybe          (Maybe (..), catMaybes, fromMaybe, isJust, isNothing,+                                      mapMaybe, maybe, maybeToList)+ import           Control.Applicative (Applicative, pure) import           Control.Monad       (Monad (..))-import           Data.Maybe          (Maybe (..))+import           Data.Monoid         (Monoid (mempty))  import           Applicative         (pass)++-- | Extracts 'Monoid' value from 'Maybe' returning 'mempty' if 'Nothing'.+--+-- >>> maybeToMonoid (Just [1,2,3] :: Maybe [Int])+-- [1,2,3]+-- >>> maybeToMonoid (Nothing :: Maybe [Int])+-- []+maybeToMonoid :: Monoid m => Maybe m -> m+maybeToMonoid = fromMaybe mempty  -- | Specialized version of 'for_' for 'Maybe'. It's used for code readability. -- Also helps to avoid space leaks:
src/Monad/Trans.hs view
@@ -8,6 +8,7 @@        , module Control.Monad.Reader        , module Control.Monad.State.Strict        , module Control.Monad.Trans+       , module Control.Monad.Trans.Identity        , module Control.Monad.Trans.Maybe           -- * Convenient functions to work with 'Reader' monad@@ -24,16 +25,19 @@        ) where  -- Monad transformers-import           Control.Monad.Except       (ExceptT (..), runExceptT)-import           Control.Monad.Reader       (MonadReader, Reader, ReaderT (..), ask, asks,-                                             local, reader, runReader)-import           Control.Monad.State.Strict (MonadState, State, StateT (..), evalState,-                                             evalStateT, execState, execStateT, gets,-                                             modify, runState, state, withState)-import           Control.Monad.Trans        (MonadIO, MonadTrans, lift, liftIO)-import           Control.Monad.Trans.Maybe  (MaybeT (..), exceptToMaybeT, maybeToExceptT)+import           Control.Monad.Except         (ExceptT (..), runExceptT)+import           Control.Monad.Reader         (MonadReader, Reader, ReaderT (..), ask,+                                               asks, local, reader, runReader)+import           Control.Monad.State.Strict   (MonadState, State, StateT (..), evalState,+                                               evalStateT, execState, execStateT, get,+                                               gets, modify, put, runState, state,+                                               withState)+import           Control.Monad.Trans          (MonadIO, MonadTrans, lift, liftIO)+import           Control.Monad.Trans.Identity (IdentityT (runIdentityT))+import           Control.Monad.Trans.Maybe    (MaybeT (..), exceptToMaybeT,+                                               maybeToExceptT) -import           Prelude                    (Functor, flip, fst, snd, (<$>))+import           Prelude                      (Functor, flip, fst, snd, (<$>))  -- | Shorter and more readable alias for @flip runReaderT@. usingReaderT :: r -> ReaderT r m a -> m a
src/Universum.hs view
@@ -26,7 +26,6 @@        , evaluateNF_        , evaluateWHNF        , evaluateWHNF_-       , guarded        , identity        , map        , pretty@@ -107,19 +106,11 @@ import           Data.HashSet             as X (HashSet) import           Data.IntMap.Strict       as X (IntMap) import           Data.IntSet              as X (IntSet)-import           Data.List                as X (break, cycle, drop, dropWhile, filter,-                                                genericDrop, genericLength,-                                                genericReplicate, genericSplitAt,-                                                genericTake, group, inits, intercalate,-                                                intersperse, isPrefixOf, iterate,-                                                permutations, repeat, replicate, reverse,-                                                scanl, scanr, sort, sortBy, splitAt,-                                                subsequences, tails, take, takeWhile,-                                                transpose, unfoldr, zip, zipWith) import           Data.Map.Strict          as X (Map) import           Data.Sequence            as X (Seq) import           Data.Set                 as X (Set) import           Data.Tuple               as X (curry, fst, snd, swap, uncurry)+import           Data.Vector              as X (Vector)  #if ( __GLASGOW_HASKELL__ >= 710 ) import           Data.Proxy               as X (Proxy (..))@@ -132,19 +123,13 @@ import           Data.Bool                as X (Bool (..), not, otherwise, (&&), (||)) import           Data.Char                as X (chr) import           Data.Int                 as X (Int, Int16, Int32, Int64, Int8)-import           Data.Maybe               as X (Maybe (..), catMaybes, fromMaybe, isJust,-                                                isNothing, mapMaybe, maybe, maybeToList) import           Data.Word                as X (Word, Word16, Word32, Word64, Word8,                                                 byteSwap16, byteSwap32, byteSwap64)  import           Data.Function            as X (const, fix, flip, on, ($), (.)) --- Generics and type level magic+-- Generics import           GHC.Generics             as X (Generic)-#if ( __GLASGOW_HASKELL__ >= 710 )-import           GHC.TypeLits             as X (CmpNat, KnownNat, KnownSymbol, Nat,-                                                SomeNat (..), natVal, someNatVal)-#endif  -- Buildable import           Data.Text.Buildable      (Buildable (build))@@ -227,18 +212,6 @@ -- Left "Prelude.read: no parse" readEither :: (ToString a, Read b) => a -> Either Text b readEither = X.first toText . Text.Read.readEither . X.toString---- | Version of 'Prelude.guard' that takes verification function.--- Can be used in some similar way:--- @---     safeSum :: Int -> Int -> Maybe Int---     safeSum a b = do---         verifiedA <- guarded (>0) a---         verifiedB <- guarded (>0) b---         pure $ verifiedA + verifiedB--- @-guarded :: (Alternative f) => (a -> Bool) -> a -> f a-guarded p x = X.bool empty (pure x) (p x)  -- | Generalized version of 'Prelude.show'. show :: (Show a, IsString b) => a -> b
universum.cabal view
@@ -1,5 +1,5 @@ name:                universum-version:             0.6.1+version:             0.7.0 synopsis:            Custom prelude used in Serokell description:         Custom prelude used in Serokell homepage:            https://github.com/serokell/universum