Merge pull request #7 from sdiehl/list-extras
all non-partial list functions
This commit is contained in:
@@ -2,9 +2,23 @@ Protolude
|
|||||||
=========
|
=========
|
||||||
|
|
||||||
[](https://travis-ci.org/sdiehl/protolude)
|
[](https://travis-ci.org/sdiehl/protolude)
|
||||||
|
[](https://hackage.haskell.org/package/protolude)
|
||||||
|
|
||||||
A sensible starting Prelude for building custom Preludes.
|
A sensible starting Prelude for building custom Preludes.
|
||||||
|
|
||||||
|
Design points:
|
||||||
|
|
||||||
|
* Banishes String.
|
||||||
|
* Banishes partial functions.
|
||||||
|
* compiler warning on bottoms.
|
||||||
|
* Foldable / Traversable by default.
|
||||||
|
* Polymorphic string IO functions.
|
||||||
|
* Automatic string conversions.
|
||||||
|
* Type synonyms for major data structures.
|
||||||
|
* Basic monad transformers in scope by default.
|
||||||
|
* Unsafe functions are prefixed with "unsafe" in separate module.
|
||||||
|
* Compiler agnostic, GHC internal modules are abstracted out into Base.
|
||||||
|
|
||||||
Supports:
|
Supports:
|
||||||
|
|
||||||
* GHC 7.6.1
|
* GHC 7.6.1
|
||||||
|
|||||||
+17
-6
@@ -16,17 +16,21 @@ import GHC.Num as X
|
|||||||
import GHC.Enum as X
|
import GHC.Enum as X
|
||||||
import GHC.Real as X
|
import GHC.Real as X
|
||||||
import GHC.Float as X
|
import GHC.Float as X
|
||||||
import GHC.Show as X
|
import GHC.Show as X (
|
||||||
|
Show(..)
|
||||||
|
)
|
||||||
import GHC.Exts as X (
|
import GHC.Exts as X (
|
||||||
Constraint
|
Constraint
|
||||||
, Ptr
|
, Ptr
|
||||||
, FunPtr
|
, FunPtr
|
||||||
, the
|
|
||||||
)
|
)
|
||||||
import GHC.Base as X (
|
import GHC.Base as X (
|
||||||
(++)
|
(++)
|
||||||
, seq
|
, seq
|
||||||
, asTypeOf
|
, asTypeOf
|
||||||
|
, ord
|
||||||
|
, maxInt
|
||||||
|
, minInt
|
||||||
)
|
)
|
||||||
import System.IO as X (
|
import System.IO as X (
|
||||||
print
|
print
|
||||||
@@ -34,11 +38,17 @@ import System.IO as X (
|
|||||||
, putStrLn
|
, putStrLn
|
||||||
)
|
)
|
||||||
|
|
||||||
#if ( __GLASGOW_HASKELL__ >= 800 )
|
import GHC.Types as X (
|
||||||
import GHC.Types as X hiding (Any)
|
Bool
|
||||||
#else
|
, Char
|
||||||
import GHC.Types as X
|
, Int
|
||||||
|
, Word
|
||||||
|
, Ordering
|
||||||
|
, IO
|
||||||
|
#if ( __GLASGOW_HASKELL__ >= 710 )
|
||||||
|
, Coercible
|
||||||
#endif
|
#endif
|
||||||
|
)
|
||||||
|
|
||||||
infixr 0 $!
|
infixr 0 $!
|
||||||
|
|
||||||
@@ -47,6 +57,7 @@ f $! x = let !vx = x in f vx
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
-- Simple Haskell Compiler
|
-- Simple Haskell Compiler
|
||||||
#if defined(__SHC_HASKELL__)
|
#if defined(__SHC_HASKELL__)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module List (
|
|||||||
head,
|
head,
|
||||||
ordNub,
|
ordNub,
|
||||||
sortOn,
|
sortOn,
|
||||||
|
list,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List (sortBy)
|
import Data.List (sortBy)
|
||||||
@@ -12,6 +13,7 @@ import Data.Maybe (Maybe(..))
|
|||||||
import Data.Ord (Ord, comparing)
|
import Data.Ord (Ord, comparing)
|
||||||
import Data.Foldable (Foldable, foldr)
|
import Data.Foldable (Foldable, foldr)
|
||||||
import Data.Function ((.))
|
import Data.Function ((.))
|
||||||
|
import Data.Functor (fmap)
|
||||||
import Control.Monad (return)
|
import Control.Monad (return)
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
@@ -30,3 +32,8 @@ ordNub l = go Set.empty l
|
|||||||
if x `Set.member` s
|
if x `Set.member` s
|
||||||
then go s xs
|
then go s xs
|
||||||
else x : go (Set.insert x s) xs
|
else x : go (Set.insert x s) xs
|
||||||
|
|
||||||
|
list :: [b] -> (a -> b) -> [a] -> [b]
|
||||||
|
list def f xs = case xs of
|
||||||
|
[] -> def
|
||||||
|
_ -> fmap f xs
|
||||||
|
|||||||
+33
-4
@@ -16,8 +16,6 @@ module Protolude (
|
|||||||
LByteString,
|
LByteString,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
{-import qualified Prelude as P-}
|
|
||||||
|
|
||||||
import List as X
|
import List as X
|
||||||
import Show as X
|
import Show as X
|
||||||
import Bool as X
|
import Bool as X
|
||||||
@@ -105,6 +103,23 @@ import Data.List as X (
|
|||||||
, reverse
|
, reverse
|
||||||
, replicate
|
, replicate
|
||||||
, take
|
, take
|
||||||
|
, sortBy
|
||||||
|
, sort
|
||||||
|
, intersperse
|
||||||
|
, transpose
|
||||||
|
, subsequences
|
||||||
|
, permutations
|
||||||
|
, scanl
|
||||||
|
, scanr
|
||||||
|
, iterate
|
||||||
|
, repeat
|
||||||
|
, cycle
|
||||||
|
, unfoldr
|
||||||
|
, takeWhile
|
||||||
|
, dropWhile
|
||||||
|
, group
|
||||||
|
, inits
|
||||||
|
, tails
|
||||||
, zipWith
|
, zipWith
|
||||||
, zip
|
, zip
|
||||||
)
|
)
|
||||||
@@ -114,6 +129,18 @@ import Data.Sequence as X (Seq)
|
|||||||
import Data.IntMap as X (IntMap)
|
import Data.IntMap as X (IntMap)
|
||||||
import Data.IntSet as X (IntSet)
|
import Data.IntSet as X (IntSet)
|
||||||
|
|
||||||
|
#if ( __GLASGOW_HASKELL__ >= 710 )
|
||||||
|
import Data.Proxy as X (
|
||||||
|
Proxy(..)
|
||||||
|
)
|
||||||
|
|
||||||
|
import Data.Void as X (
|
||||||
|
Void
|
||||||
|
, absurd
|
||||||
|
, vacuous
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
-- Monad transformers
|
-- Monad transformers
|
||||||
import Control.Monad.State as X (
|
import Control.Monad.State as X (
|
||||||
MonadState
|
MonadState
|
||||||
@@ -166,7 +193,7 @@ import Data.Int as X
|
|||||||
import Data.Bits as X
|
import Data.Bits as X
|
||||||
import Data.Word as X
|
import Data.Word as X
|
||||||
import Data.Bool as X hiding (bool)
|
import Data.Bool as X hiding (bool)
|
||||||
import Data.Char as X (Char)
|
import Data.Char as X (chr)
|
||||||
import Data.Maybe as X hiding (fromJust)
|
import Data.Maybe as X hiding (fromJust)
|
||||||
import Data.Either as X
|
import Data.Either as X
|
||||||
import Data.Complex as X
|
import Data.Complex as X
|
||||||
@@ -180,7 +207,6 @@ import Data.Function as X (
|
|||||||
, on
|
, on
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
-- Genericss
|
-- Genericss
|
||||||
import GHC.Generics (
|
import GHC.Generics (
|
||||||
Generic(..)
|
Generic(..)
|
||||||
@@ -222,6 +248,8 @@ import Data.String.Conv as X (
|
|||||||
, StringConv
|
, StringConv
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import Data.String as X (IsString)
|
||||||
|
|
||||||
-- Printf
|
-- Printf
|
||||||
import Text.Printf as X (
|
import Text.Printf as X (
|
||||||
PrintfArg
|
PrintfArg
|
||||||
@@ -231,6 +259,7 @@ import Text.Printf as X (
|
|||||||
|
|
||||||
-- IO
|
-- IO
|
||||||
import System.Exit as X
|
import System.Exit as X
|
||||||
|
--import System.Info as X
|
||||||
import System.Environment as X (getArgs)
|
import System.Environment as X (getArgs)
|
||||||
import System.IO as X (
|
import System.IO as X (
|
||||||
Handle
|
Handle
|
||||||
|
|||||||
Reference in New Issue
Block a user