packages feed

universum 0.1.12 → 0.2

raw patch · 11 files changed

+269/−83 lines, 11 filesdep +microlensdep +microlens-mtldep +vectordep ~basenew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: microlens, microlens-mtl, vector

Dependency ranges changed: base

API changes (from Hackage documentation)

- Panic: [msg] :: FatalError -> Text
- Universum: (&) :: a -> (a -> b) -> b
- Universum: infixl 1 &
+ Containers: class One x where type OneItem x where {
+ Containers: instance Containers.One (Data.IntMap.Base.IntMap v)
+ Containers: instance Containers.One (Data.List.NonEmpty.NonEmpty a)
+ Containers: instance Containers.One (Data.Map.Base.Map k v)
+ Containers: instance Containers.One (Data.Set.Base.Set v)
+ Containers: instance Containers.One (Data.Vector.Vector a)
+ Containers: instance Containers.One Data.ByteString.Internal.ByteString
+ Containers: instance Containers.One Data.ByteString.Lazy.Internal.ByteString
+ Containers: instance Containers.One Data.IntSet.Base.IntSet
+ Containers: instance Containers.One Data.Text.Internal.Lazy.Text
+ Containers: instance Containers.One Data.Text.Internal.Text
+ Containers: instance Containers.One [a]
+ Containers: instance Data.Hashable.Class.Hashable k => Containers.One (Data.HashMap.Base.HashMap k v)
+ Containers: instance Data.Hashable.Class.Hashable v => Containers.One (Data.HashSet.HashSet v)
+ Containers: instance Data.Primitive.Types.Prim a => Containers.One (Data.Vector.Primitive.Vector a)
+ Containers: instance Data.Vector.Unboxed.Base.Unbox a => Containers.One (Data.Vector.Unboxed.Base.Vector a)
+ Containers: instance Foreign.Storable.Storable a => Containers.One (Data.Vector.Storable.Vector a)
+ Containers: one :: One x => OneItem x -> x
+ Containers: type family OneItem x;
+ Containers: }
+ Functor: (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
+ Panic: [fatalErrorMessage] :: FatalError -> Text
- Exceptions: note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a
+ Exceptions: note :: (MonadError e m) => e -> Maybe a -> m a
- Functor: infixl 4 <$>
+ Functor: infixl 4 <<$>>

Files

CHANGES.md view
@@ -1,3 +1,26 @@+0.2+===++* Add `one` (similar to `singleton`).+* Expose `Symbol` and `Nat` types from `GHC.TypeLits` by default.+* Export `genericLength` and other generic list return functions.+* Rename `msg` to `fatalErrorMessage`.+* Export `ExceptT`+* Export `ReaderT`, and `StateT` constructors.+* Export `NonEmpty` type and constructor for Base 4.9 only.+* Export `Data.Semigroup` type and functions for Base 4.9 only.+* Export `String`.++0.1.13+======++* Add lenses from `microlens`.+* Add `(<&>)`.+* Reexport `(&)` from `Data.Function` if it's present there instead+  of always defining our own (this is actually done by reexporting it+  from `Lens.Micro` which does the right thing).+* Fix a space leak in `whenJust`.+ 0.1.12 ====== @@ -10,8 +33,8 @@ 0.1.11 ====== -* Add specialized print functions for `ByteString`-* Export more stuff from `Semigroup` and use `(<>)` from `Monoid`+* Expose `putByteString` and `putLByteString` monomorphic versions of `putStrLn` functions+* Switch exported `(<>)` to be from `Data.Monoid` instead of Semigroup. * Export `Hashable`  0.1.10@@ -59,3 +82,5 @@  0.1.5 =====++* Initial release.
LICENSE view
@@ -1,5 +1,5 @@ The MIT License (MIT)-Copyright (c) 2016, Stephen Diehl+Copyright (c) 2016-2017, Stephen Diehl, 2017, Serokell  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to
src/Base.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE BangPatterns       #-} {-# LANGUAGE CPP                #-} {-# LANGUAGE ExplicitNamespaces #-}-{-# LANGUAGE NoImplicitPrelude  #-} {-# LANGUAGE Unsafe             #-}  module Base@@ -13,22 +12,30 @@ #if defined(__GLASGOW_HASKELL__) && ( __GLASGOW_HASKELL__ >= 600 )  -- Base GHC types-import           GHC.Base             as X (asTypeOf, maxInt, minInt, ord, seq, (++))-import           GHC.Enum             as X+import           GHC.Base             as X (String, asTypeOf, maxInt, minInt, ord, seq,+                                            (++))+import           GHC.Enum             as X (Bounded (..), Enum (..), boundedEnumFrom,+                                            boundedEnumFromThen) import           GHC.Err              as X (error, undefined) import           GHC.Exts             as X (Constraint, FunPtr, Ptr)-import           GHC.Float            as X-import           GHC.Num              as X+import           GHC.Float            as X (Double (..), Float (..), Floating (..),+                                            showFloat, showSignedFloat)+import           GHC.Num              as X (Integer, Num (..), subtract) import           GHC.Real             as X hiding ((%)) import           GHC.Show             as X (Show (..)) import           System.IO            as X (print, putStr, putStrLn)  import           GHC.Types            as X (Bool, Char, IO, Int, Ordering, Word) + #if ( __GLASGOW_HASKELL__ >= 710 ) import           GHC.Types            as X (Coercible) #endif +#if ( __GLASGOW_HASKELL__ >= 710 )+import           GHC.StaticPtr        as X (StaticPtr)+#endif+ #if ( __GLASGOW_HASKELL__ >= 800 ) import           GHC.OverloadedLabels as X (IsLabel (..)) @@ -37,16 +44,33 @@  import           GHC.Stack            as X (CallStack, HasCallStack, callStack,                                             currentCallStack, getCallStack,-                                            prettyCallStack, prettySrcLoc)+                                            prettyCallStack, prettySrcLoc,+                                            withFrozenCallStack) +#if ( __GLASGOW_HASKELL__ >= 710 )+import           GHC.TypeLits         as X (CmpNat, KnownNat, KnownSymbol, Nat,+                                            SomeNat (..), SomeSymbol (..), Symbol, natVal,+                                            someNatVal, someSymbolVal, symbolVal)+#endif++-- Pending GHC 8.2 we'll expose these.+ {- import GHC.Records as X (     HasField(..)   )++<<<<<<< HEAD+=======+import Data.Kind as X (+    type (*)+  , type Type+  ) -}  #endif +-- Default Prelude defines this at the toplevel module, so we do as well. infixr 0 $!  ($!) :: (a -> b) -> a -> b
src/Containers.hs view
@@ -12,7 +12,9 @@ {-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}  module Containers-       ( Element+       (+       -- * Foldable-like classes and methods+         Element        , Container(..)        , NontrivialContainer(..) @@ -26,6 +28,9 @@        , sequenceA_        , sequence_        , asum++       -- * Others+       , One(..)        ) where  import           Control.Applicative    (Alternative (..))@@ -44,15 +49,30 @@ import           GHC.TypeLits           (ErrorMessage (..), TypeError) #endif +#if ( __GLASGOW_HASKELL__ >= 800 )+import qualified Data.List.NonEmpty     as NE+#endif+ import qualified Data.ByteString        as BS import qualified Data.ByteString.Lazy   as BSL  import qualified Data.Text              as T import qualified Data.Text.Lazy         as TL +import qualified Data.Map               as M+import qualified Data.Set               as S+import qualified Data.IntMap            as IM import qualified Data.IntSet            as IS+import qualified Data.HashMap.Strict    as HM+import qualified Data.HashSet           as HS +import qualified Data.Vector            as V+import qualified Data.Vector.Unboxed    as VU+import qualified Data.Vector.Primitive  as VP+import qualified Data.Vector.Storable   as VS +import Data.Hashable (Hashable)+ ---------------------------------------------------------------------------- -- Containers (e.g. tuples aren't containers) ----------------------------------------------------------------------------@@ -442,6 +462,107 @@ DISALLOW_NONTRIVIAL_CONTAINER_7(Identity a) DISALLOW_NONTRIVIAL_CONTAINER_7(Either a b) #endif++----------------------------------------------------------------------------+-- One+----------------------------------------------------------------------------++class One x where+    type OneItem x+    -- | Create a list, map, 'Text', etc from a single element.+    one :: OneItem x -> x++-- Lists++instance One [a] where+    type OneItem [a] = a+    one = (:[])+    {-# INLINE one #-}++#if ( __GLASGOW_HASKELL__ >= 800 )+instance One (NE.NonEmpty a) where+    type OneItem (NE.NonEmpty a) = a+    one = (NE.:|[])+    {-# INLINE one #-}+#endif++-- Monomorphic sequences++instance One T.Text where+    type OneItem T.Text = Char+    one = T.singleton+    {-# INLINE one #-}++instance One TL.Text where+    type OneItem TL.Text = Char+    one = TL.singleton+    {-# INLINE one #-}++instance One BS.ByteString where+    type OneItem BS.ByteString = Word8+    one = BS.singleton+    {-# INLINE one #-}++instance One BSL.ByteString where+    type OneItem BSL.ByteString = Word8+    one = BSL.singleton+    {-# INLINE one #-}++-- Maps++instance One (M.Map k v) where+    type OneItem (M.Map k v) = (k, v)+    one = uncurry M.singleton+    {-# INLINE one #-}++instance Hashable k => One (HM.HashMap k v) where+    type OneItem (HM.HashMap k v) = (k, v)+    one = uncurry HM.singleton+    {-# INLINE one #-}++instance One (IM.IntMap v) where+    type OneItem (IM.IntMap v) = (Int, v)+    one = uncurry IM.singleton+    {-# INLINE one #-}++-- Sets++instance One (S.Set v) where+    type OneItem (S.Set v) = v+    one = S.singleton+    {-# INLINE one #-}++instance Hashable v => One (HS.HashSet v) where+    type OneItem (HS.HashSet v) = v+    one = HS.singleton+    {-# INLINE one #-}++instance One IS.IntSet where+    type OneItem IS.IntSet = Int+    one = IS.singleton+    {-# INLINE one #-}++-- Vectors++instance One (V.Vector a) where+    type OneItem (V.Vector a) = a+    one = V.singleton+    {-# INLINE one #-}++instance VU.Unbox a => One (VU.Vector a) where+    type OneItem (VU.Vector a) = a+    one = VU.singleton+    {-# INLINE one #-}++instance VP.Prim a => One (VP.Vector a) where+    type OneItem (VP.Vector a) = a+    one = VP.singleton+    {-# INLINE one #-}++instance VS.Storable a => One (VS.Vector a) where+    type OneItem (VS.Vector a) = a+    one = VS.singleton+    {-# INLINE one #-}  ---------------------------------------------------------------------------- -- Utils
src/Exceptions.hs view
@@ -1,5 +1,5 @@+{-# LANGUAGE CPP                   #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE NoImplicitPrelude     #-} {-# LANGUAGE Trustworthy           #-}  module Exceptions@@ -22,8 +22,14 @@ hush (Left _)  = empty hush (Right x) = pure x +-- To suppress redundenet applicative constraint warning on GHC 8.0+#if ( __GLASGOW_HASKELL__ >= 800 )+note :: (MonadError e m) => e -> Maybe a -> m a+note err = maybe (throwError err) pure+#else note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a note err = maybe (throwError err) pure+#endif  tryIO :: MonadIO m => IO a -> ExceptT IOException m a tryIO = ExceptT . liftIO . Exception.try
src/Functor.hs view
@@ -7,23 +7,12 @@        , void        , ($>)        , (<$>)+       , (<<$>>)        ) where -#if (__GLASGOW_HASKELL__ >= 710)+import           Data.Function ((.)) import           Data.Functor  (Functor (..), void, ($>), (<$>))-#else-import           Data.Function (flip, (.))-import           Data.Functor  (Functor (..), (<$>)) -infixl 4 $>--($>) :: Functor f => f a -> b -> f b-($>) = flip (<$)---- TODO: define it properly to be able to export+infixl 4 <<$>> (<<$>>) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b) (<<$>>) = fmap . fmap--void :: Functor f => f a -> f ()-void x = () <$ x-#endif
src/List.hs view
@@ -1,10 +1,9 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE Safe              #-}+{-# LANGUAGE Safe #-}  module List-       ( ordNub+       ( list+       , ordNub        , sortOn-       , list        , unzip        , unzip3        , zip
src/Monad.hs view
@@ -50,8 +50,7 @@        ) where  import           Base                            (IO, seq)-import           Control.Applicative             (Applicative)-import           Data.Foldable                   (for_)+import           Control.Applicative             (Applicative, pure) import           Data.List                       (concat) import           Data.Maybe                      (Maybe (..), maybe) import           Prelude                         (Bool (..))@@ -94,7 +93,8 @@ {-# INLINE (<$!>) #-}  whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()-whenJust = for_+whenJust (Just x) f = f x+whenJust Nothing _  = pure () {-# INLINE whenJust #-}  whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
src/Panic.hs view
@@ -12,7 +12,7 @@ import           Data.Typeable     (Typeable)  -- | Uncatchable exceptions thrown and never caught.-data FatalError = FatalError { msg :: Text }+data FatalError = FatalError { fatalErrorMessage :: Text }   deriving (Show, Typeable)  instance Exception FatalError
src/Universum.hs view
@@ -17,7 +17,6 @@          -- * Useful standard unclassifed functions        , identity        , map-       , (&)        , uncons        , unsnoc        , applyN@@ -41,6 +40,7 @@ import           Conv                     as X import           Debug                    as X import           Either                   as X+import           Exceptions               as X import           Functor                  as X import           Lifted                   as X import           List                     as X@@ -53,8 +53,6 @@                                                    showSignedFloat, showsPrec, undefined) import qualified Base                     as PBase --- Used for 'show', not exported.-import           Data.String              (String) import           Data.String              as X (IsString (..))  -- Maybe'ized version of partial functions@@ -69,14 +67,16 @@                                                 liftA3, optional, (<**>))  -- Base typeclasses-import           Data.Eq                  as X+import           Data.Eq                  as X (Eq (..)) import           Data.Foldable            as X (Foldable, concat, concatMap, foldlM,                                                 foldrM, maximumBy, minimumBy)-import           Data.Functor.Identity    as X-import           Data.Ord                 as X+import           Data.Functor.Identity    as X (Identity (..))+import           Data.Ord                 as X (Down (..), Ord (..), Ordering (..),+                                                comparing) import           Data.Traversable         as X hiding (for)  #if ( __GLASGOW_HASKELL__ >= 800 )+import           Data.List.NonEmpty       as X (NonEmpty (..), nonEmpty) import           Data.Monoid              as X import           Data.Semigroup           as X (Option (..), Semigroup (sconcat, stimes),                                                 WrappedMonoid, cycle1, mtimesDefault,@@ -96,23 +96,24 @@ import           Control.DeepSeq          as X (NFData (..), deepseq, force, ($!!))  -- Data structures-import           Data.List                as X (break, cycle, drop, dropWhile, filter,-                                                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.Tuple               as X- import           Data.Hashable            as X (Hashable) import           Data.HashMap.Strict      as X (HashMap) 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)  #if ( __GLASGOW_HASKELL__ >= 710 ) import           Data.Proxy               as X (Proxy (..))@@ -124,13 +125,13 @@ import           Control.Monad.Catch      as X (MonadCatch (catch), MonadMask (..),                                                 MonadThrow (throwM), bracket, bracket_,                                                 catchAll, finally)-import           Control.Monad.State      as X (MonadState, State, StateT, evalState,+import           Control.Monad.Except     as X (ExceptT (..), runExceptT)+import           Control.Monad.State      as X (MonadState, State, StateT (..), evalState,                                                 evalStateT, execState, execStateT, gets,-                                                modify, runState, runStateT, state,-                                                withState)+                                                modify, runState, state, withState) -import           Control.Monad.Reader     as X (MonadReader, Reader, ReaderT, ask, asks,-                                                local, reader, runReader, runReaderT)+import           Control.Monad.Reader     as X (MonadReader, Reader, ReaderT (..), ask,+                                                asks, local, reader, runReader)  import           Control.Monad.Trans      as X (MonadIO, lift, liftIO) @@ -138,16 +139,23 @@ import           Data.Bits                as X hiding (unsafeShiftL, unsafeShiftR) import           Data.Bool                as X hiding (bool) import           Data.Char                as X (chr)-import           Data.Complex             as X-import           Data.Either              as X-import           Data.Int                 as X+import           Data.Either              as X (Either (..), either, isLeft, isRight,+                                                lefts, partitionEithers, rights)+import           Data.Int                 as X (Int, Int16, Int32, Int64, Int8) import           Data.Maybe               as X hiding (fromJust)-import           Data.Word                as X+import           Data.Word                as X (Word, Word16, Word32, Word64, Word8,+                                                byteSwap16, byteSwap32, byteSwap64)  import           Data.Function            as X (const, fix, flip, on, ($), (.)) --- Generics+-- Generics and type level magic import           GHC.Generics             as X (Generic)+#if ( __GLASGOW_HASKELL__ >= 710 )+import           GHC.TypeLits             as X (CmpNat, KnownNat, KnownSymbol, Nat,+                                                SomeNat (..), SomeSymbol (..), Symbol,+                                                natVal, someNatVal, someSymbolVal,+                                                symbolVal)+#endif  -- Buildable import           Data.Text.Buildable      (Buildable (build))@@ -164,15 +172,15 @@ import           Data.Text.Lazy           as X (fromStrict, toStrict)  import           Data.Text.Encoding       as X (decodeUtf8', decodeUtf8With)+import           Data.Text.Encoding.Error as X (OnDecodeError, OnError, UnicodeException,+                                                lenientDecode, strictDecode)  -- IO-import           System.Exit              as X hiding (die, exitFailure, exitSuccess,-                                                exitWith) import           System.IO                as X (FilePath, Handle, IOMode (..), stderr,                                                 stdin, stdout, withFile)  -- ST-import           Control.Monad.ST         as X hiding (stToIO)+import           Control.Monad.ST         as X (ST, fixST, runST)  -- Concurrency and Parallelism import           Control.Exception        as X (Exception, SomeException (..))@@ -182,22 +190,33 @@                                                 mkWeakThreadId, myThreadId,                                                 setNumCapabilities, threadCapability,                                                 throwTo)-import           Control.Concurrent.Async as X hiding (wait)-import           Control.Monad.STM        as X hiding (atomically)+import           Control.Concurrent.Async as X (Async (..), Concurrently (..), async,+                                                asyncBound, asyncOn, asyncThreadId,+                                                cancel, cancelWith, concurrently, link,+                                                link2, poll, race, race_, waitAny,+                                                waitAnyCancel, waitAnyCatch,+                                                waitAnyCatchCancel, waitBoth, waitCatch,+                                                waitEither, waitEitherCancel,+                                                waitEitherCatch, waitEitherCatchCancel,+                                                waitEither_, withAsync, withAsyncBound,+                                                withAsyncOn)+import           Control.Monad.STM        as X (STM, always, alwaysSucceeds, catchSTM,+                                                check, orElse, retry, throwSTM)  import           Foreign.Storable         as X (Storable)  -- Read instances hiding unsafe builtins (read) import           Text.Read                as X (Read, readEither, readMaybe, reads) --- Type synonymss for lazy texts+-- Lenses+import           Lens.Micro               as X (Lens, Lens', Traversal, Traversal', over,+                                                set, (%~), (&), (.~), (<&>), (^.), (^..),+                                                (^?), _1, _2, _3, _4, _5)+import           Lens.Micro.Mtl           as X (preuse, preview, use, view)++-- Type synonyms for lazy types type LText = Data.Text.Lazy.Text type LByteString = Data.ByteString.Lazy.ByteString--infixl 1 &--(&) :: a -> (a -> b) -> b-x & f = f x  identity :: a -> a identity x = x
universum.cabal view
@@ -1,5 +1,5 @@ name:                universum-version:             0.1.12+version:             0.2 synopsis:            Custom prelude used in Serokell description:         Custom prelude used in Serokell homepage:            https://github.com/serokell/universum@@ -53,22 +53,25 @@     -fwarn-implicit-prelude    build-depends:-    async                 >= 2.1  && <2.2,-    base                  >= 4.6  && <4.10,-    bytestring            >= 0.10 && <0.11,-    containers            >= 0.5  && <0.6,-    deepseq               >= 1.3  && <1.5,+    async                 >= 2.1    && <2.2,+    base                  >= 4.7    && <4.10,+    bytestring            >= 0.10   && <0.11,+    containers            >= 0.5    && <0.6,+    deepseq               >= 1.3    && <1.5,     exceptions,-    ghc-prim              >= 0.3  && <0.6,+    ghc-prim              >= 0.3    && <0.6,     hashable,-    mtl                   >= 2.1  && <2.3,-    safe                  >= 0.3  && <0.4,-    stm                   >= 2.4  && <2.5,-    text                  >= 1.2  && <1.3,-    utf8-string           >= 1.0  && <1.1,+    microlens             >= 0.4    && <0.5,+    microlens-mtl         >= 0.1.7  && <0.2,+    mtl                   >= 2.1    && <2.3,+    safe                  >= 0.3    && <0.4,+    stm                   >= 2.4    && <2.5,+    text                  >= 1.2    && <1.3,+    utf8-string           >= 1.0    && <1.1,     text-format,-    transformers          >= 0.4  && <0.6,-    unordered-containers+    transformers          >= 0.4    && <0.6,+    unordered-containers,+    vector    hs-source-dirs:      src   default-language:    Haskell2010