packages feed

data-extra 2.5.4 → 2.5.5

raw patch · 13 files changed

+5/−458 lines, 13 filesdep −basedep −mtldep −old-locale

Dependencies removed: base, mtl, old-locale, text, time

Files

− LICENSE
@@ -1,30 +0,0 @@-Copyright (c) 2013, Chris Done--All rights reserved.--Redistribution and use in source and binary forms, with or without-modification, are permitted provided that the following conditions are met:--    * Redistributions of source code must retain the above copyright-      notice, this list of conditions and the following disclaimer.--    * Redistributions in binary form must reproduce the above-      copyright notice, this list of conditions and the following-      disclaimer in the documentation and/or other materials provided-      with the distribution.--    * Neither the name of Chris Done nor the names of other-      contributors may be used to endorse or promote products derived-      from this software without specific prior written permission.--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data-extra.cabal view
@@ -1,32 +1,9 @@ name:                data-extra-version:             2.5.4-synopsis:            Extra utilities for working on Data.* types.-description:         Extra utilities for working on Data.* types.+version:             2.5.5+synopsis:            None+description:         None license:             BSD3-license-file:        LICENSE-author:              Chris Done, Sam Levy-maintainer:          chrisdone@gmail.com-copyright:           2013 Chris Done-category:            Data+author:              None build-type:          Simple-cabal-version:       >=1.8-+cabal-version:       >=1.2 library-  exposed-modules:   Data.Extra,-                     Data.Either.Extra,-                     Data.Maybe.Extra,-                     Data.Bool.Extra,-                     Data.List.Extra,-                     Data.String.Extra,-                     Data.Text.Extra,-                     Data.Number.Extra,-                     Data.Time.Extra,-                     Data.Tuple.Extra,-                     Data.Eq.Extra-  hs-source-dirs:    src/-  build-depends:     base > 4 && <5,-                     text,-                     old-locale,-                     time,-                     mtl-  ghc-options:       -Wall
− src/Data/Bool/Extra.hs
@@ -1,14 +0,0 @@--- | Extra functions for dealing with Bool.--module Data.Bool.Extra-  (bool-  ,cond)-  where---- | bool false true p = if p then true else false-bool :: a -> a -> Bool -> a-bool false true p = if p then true else false---- | cond false true p v = if p v then true v else false v-cond :: (a -> b) -> (a -> b) -> (a -> Bool) -> a -> b-cond false true p v = if p v then true v else false v
− src/Data/Either/Extra.hs
@@ -1,45 +0,0 @@--- | Extra functions for dealing with Either.--module Data.Either.Extra where---- | A map for Either values.-mapEither :: (a -> b1) -> (b -> b2) -> Either a b -> Either b1 b2-mapEither l r = either (Left . l) (Right . r)---- | Maybe get the left side of an Either.-leftToMaybe :: Either a b -> Maybe a-leftToMaybe = either Just (const Nothing)---- | Maybe get the right side of an Either.-rightToMaybe :: Either a b -> Maybe b-rightToMaybe = either (const Nothing) Just---- | Is a value Left?-isLeft :: Either a b -> Bool-isLeft (Left _) = True-isLeft (Right _) = False---- | Is a value Right?-isRight :: Either a b -> Bool-isRight (Left _) = False-isRight (Right _) = True---- | Extract the left value or a default.-fromLeft :: a -> Either a b -> a-fromLeft _ (Left x) = x-fromLeft x _ = x---- | Extract the right value or a default.-fromRight :: b -> Either a b -> b-fromRight _ (Right x) = x-fromRight x _ = x---- | When a value is Right, do something with it, monadically.-whenRight :: Monad m => Either a b -> (b -> m c) -> m ()-whenRight (Right x) m = m x >> return ()-whenRight _         _ = return ()---- | When a value is Left, do something with it, monadically.-whenLeft :: Monad m => Either a b -> (a -> m c) -> m ()-whenLeft (Left x) m = m x >> return ()-whenLeft _         _ = return ()
− src/Data/Eq/Extra.hs
@@ -1,9 +0,0 @@--- | Extra utilities for equality.--module Data.Eq.Extra where--import Data.Function---- | Apply a function before passing it to equality.-equating :: Eq b => (a -> b) -> a -> a -> Bool-equating = on (==)
− src/Data/Extra.hs
@@ -1,38 +0,0 @@--- | Extra Data.* functions.--module Data.Extra-       (module Data.Either-       ,module Data.Either.Extra-       ,module Data.Maybe-       ,module Data.Maybe.Extra-       ,module Data.List-       ,module Data.List.Extra-       ,module Data.Bool-       ,module Data.Bool.Extra-       ,module Data.String-       ,module Data.String.Extra-       ,module Data.Text.Extra-       ,module Data.Time-       ,module Data.Time.Extra-       ,module Data.Number.Extra-       ,module Data.Tuple.Extra-       ,module Data.Eq.Extra-       )-      where--import Data.Either-import Data.Either.Extra-import Data.Maybe-import Data.Maybe.Extra-import Data.List-import Data.List.Extra-import Data.Bool-import Data.Bool.Extra-import Data.String-import Data.String.Extra-import Data.Text.Extra-import Data.Time-import Data.Time.Extra-import Data.Number.Extra-import Data.Tuple.Extra-import Data.Eq.Extra
− src/Data/List/Extra.hs
@@ -1,42 +0,0 @@--- | Extra functions for dealing with lists.--module Data.List.Extra where--import Control.Arrow-import Data.Bool.Extra-import Data.List-import Data.Maybe-import Data.Ord---- | When a list is non-null, pass it to a function, otherwise use the--- default.-list :: b -> ([a] -> b) -> [a] -> b-list nil cons = cond (const nil) cons null---- | Get the union of the given lists.-unionOf :: (Eq a) => [[a]] -> [a]-unionOf = foldr union []---- | Opposite of map.-for :: [a] -> (a -> b) -> [b]-for = flip map---- | Maybe get the last element in the list.-lastToMaybe :: [a] -> Maybe a-lastToMaybe [x]    = Just x-lastToMaybe (_:xs) = lastToMaybe xs-lastToMaybe []     = Nothing---- | Return the first item of a list or something else.-firstOr :: a -> [a] -> a-firstOr n = fromMaybe n . listToMaybe---- | Get the maximum of a list or return zero.-maxList :: (Num t, Ord t) => [t] -> t-maxList [] = 0-maxList xs = maximum xs---- | Sort a list using a key on each element.  This implements the---   decorate-sort-undecorate paradigm, also called a Schwarzian transform.-sortByKey :: Ord b => (a -> b) -> [a] -> [a]-sortByKey f = map snd . sortBy (comparing fst) . map (f &&& id)
− src/Data/Maybe/Extra.hs
@@ -1,20 +0,0 @@--- | Extra functions for dealing with Maybe.--module Data.Maybe.Extra where--import Control.Monad---- | When the predicate is true, return maybe the action's return value.-whenMaybe :: Monad m => Bool -> m a -> m (Maybe a)-whenMaybe False _ = return Nothing-whenMaybe True m = liftM Just m---- | When a value is Just, do something with it, monadically.-whenJust :: Monad m => Maybe a -> (a -> m c) -> m ()-whenJust (Just a) m = m a >> return ()-whenJust _         _ = return ()---- | Return the sole element of the list or nothing.-sole :: [a] -> Maybe a-sole [x] = Just x-sole _   = Nothing
− src/Data/Number/Extra.hs
@@ -1,63 +0,0 @@--- | Extra functions for numbers.--module Data.Number.Extra where--{-# INLINE towardZero          #-}-{-# INLINE towardInf           #-}-{-# INLINE towardNegInf        #-}-{-# INLINE awayFromZero        #-}-{-# INLINE nearestTowardZero   #-}-{-# INLINE nearestTowardInf    #-}-{-# INLINE nearestTowardNegInf #-}-{-# INLINE nearestAwayFromZero #-}-{-# INLINE nearestBanker       #-}---- | Round toward zero (truncate).-towardZero :: (Integral b, RealFrac a) => a -> b-towardZero = truncate---- | Round upwards (ceiling).-towardInf :: (Integral b, RealFrac a) => a -> b-towardInf = ceiling---- | Round backwards (floor).-towardNegInf :: (Integral b, RealFrac a) => a -> b-towardNegInf = floor---- | Round away from zero (ceiling if positive, floor otherwise).-awayFromZero :: (Integral b, RealFrac a) => a -> b-awayFromZero v = if v > 0 then ceiling v else floor v---- | Round torwards zero (if half go towards zero, otherwise up to 1).-nearestTowardZero :: (Integral b, RealFrac a) => a -> b-nearestTowardZero v = if isHalf v then towardZero   v else round v---- | Same as "nearestTowardZero" but to infinity instead of zero.-nearestTowardInf :: (Integral b, RealFrac a) => a -> b-nearestTowardInf v = if isHalf v then towardInf    v else round v---- | Same as "nearestTowardZero" but towards negative instead of zero.-nearestTowardNegInf :: (Integral b, RealFrac a) => a -> b-nearestTowardNegInf v = if isHalf v then towardNegInf v else round v---- | Same as "nearestTowardZero" but rounds away from zero (by positive or negative).-nearestAwayFromZero :: (Integral b, RealFrac a) => a -> b-nearestAwayFromZero v = if isHalf v then awayFromZero v else round v---- | Round up (round).-nearestBanker :: (Integral b, RealFrac a) => a -> b-nearestBanker = round--{-# INLINE fi #-}--- | Short-hand for fromIntegral.-fi :: (Integral a, Num b) => a -> b-fi = fromIntegral--{-# INLINE isHalf #-}--- | Is a number rounded down 0.5?-isHalf :: RealFrac a => a -> Bool-isHalf v = v - fromInteger (towardNegInf v) == 0.5---- | Short-hand for fromIntegral. Deprecated in favour of the more popular fi.-int :: (Integral a, Num b) => a -> b-int = fromIntegral
− src/Data/String/Extra.hs
@@ -1,27 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeSynonymInstances #-}---- | Extra functions and classes for dealing with Strings.--module Data.String.Extra where--import Data.Char---- | Lower case a string.-lower :: String -> String-lower = map toLower---- | Upper case a string.-upper :: String -> String-upper = map toUpper---- | Trim a string.-trim :: [Char] -> [Char]-trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace---- | A class for converting to strings.-class ToString a where-  toString :: a -> String--instance ToString String where-  toString = id
− src/Data/Text/Extra.hs
@@ -1,56 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE OverloadedStrings #-}---- | Extra functions and classes for dealing with Text.--module Data.Text.Extra where--import           Data.Number.Extra-import           Data.Text-import qualified Data.Text.Lazy as L---- | A class for converting to Text.-class ToText a where-  toText :: a -> Text-  toLazyText :: a -> L.Text--instance ToText Text where-  toText = id-  toLazyText = L.fromStrict--instance ToText String where-  toText = pack-  toLazyText = L.pack---- | A class for converting from Text.-class FromText a where-  fromText :: Text -> Maybe a-  fromLazyText :: L.Text -> Maybe a--instance FromText String where-  fromText = Just . unpack-  fromLazyText = Just . L.unpack---- | Big 'em up.-bigUp :: (Integral a) => a -> Text-bigUp = go . int where-  go :: Integer -> Text-  go n | n < 3              = "a couple"-       | n < 5              = "several"-       | n < 10             = "many"-       | n < 80             = "dozens"-       | n < 100            = "nearly a hundred"-       | n < 200            = "some hundred"-       | n < 1000           = "hundreds"-       | n < 10000          = "thousands"-       | n < 100000         = "tens of thousands"-       | n < 200000         = "a hundred thousand"-       | n < 500000         = "hundreds of thousands"-       | n < 500000         = "half a million"-       | n < 600000         = "over half a million"-       | n < 1000000        = "nearly a million"-       | n < 2000000        = "over a million"-       | n < (10^ (9::Int)) = "millions"-       | n < 10^ (12::Int)  = "billions"-       | otherwise          = "trillions"
− src/Data/Time/Extra.hs
@@ -1,79 +0,0 @@-{-# LANGUAGE BangPatterns #-}---- | Extra date functions.--module Data.Time.Extra where--import Control.Monad.Trans-import Data.List-import Data.Text (Text,pack)-import Data.Time-import System.Locale-import Text.Printf---- | Get the current year.-getYear :: FormatTime t => t -> Integer-getYear = read . formatTime defaultTimeLocale "%Y"---- | Get the current month.-getMonth :: FormatTime t => t -> Integer-getMonth = read . formatTime defaultTimeLocale "%m"---- | Get the current day.-getDay :: FormatTime t => t -> Integer-getDay = read . formatTime defaultTimeLocale "%d"---- | Display a time span as one time relative to another.-relative :: UTCTime -- ^ The later time span.-         -> UTCTime -- ^ The earlier time span.-         -> Bool    -- ^ Display 'in/ago'?-         -> Text    -- ^ Example: '3 seconds ago', 'in three days'.-relative t1 t2 fix = pack $ maybe "unknown" format $ find (\(s,_,_) -> abs span'>=s) $ reverse ranges where-  minute = 60; hour = minute * 60; day = hour * 24;-  week = day * 7; month = day * 30; year = month * 12-  format range =-    (if fix && span'>0 then "in " else "")-    ++ case range of-        (_,str,0) -> str-        (_,str,base) -> printf str (abs $ round (span' / base) :: Integer)-    ++ (if fix && span'<0 then " ago" else "")-  span' = t1 `diffUTCTime` t2-  ranges = [(0,"%d seconds",1)-           ,(minute,"a minute",0)-           ,(minute*2,"%d minutes",minute)-           ,(minute*30,"half an hour",0)-           ,(minute*31,"%d minutes",minute)-           ,(hour,"an hour",0)-           ,(hour*2,"%d hours",hour)-           ,(hour*3,"a few hours",0)-           ,(hour*4,"%d hours",hour)-           ,(day,"a day",0)-           ,(day*2,"%d days",day)-           ,(week,"a week",0)-           ,(week*2,"%d weeks",week)-           ,(month,"a month",0)-           ,(month*2,"%d months",month)-           ,(year,"a year",0)-           ,(year*2,"%d years",year)-           ]---- | Run a stop-watch at the start and end of a computation.-stopwatch :: MonadIO m => m a -> m (a,NominalDiffTime)-stopwatch computation = do-  start <- liftIO $ getCurrentTime-  !a <- computation-  end <- liftIO $ getCurrentTime-  return (a,end `diffUTCTime` start)---- | Trivial benchmark for some monadic action.-bench :: MonadIO m => Integer -> m a -> m (a,NominalDiffTime)-bench i computation = go i (Nothing,0) where-  go n (Nothing,_) = do-    (a,time) <- stopwatch computation-    go (n-1) (Just a,time)-  go 0 (Just x,avg) = do-    return (x, avg)-  go n (Just _,avg) = do-    (a,new) <- stopwatch computation-    go (n-1) (Just a,(new + avg*cnt) / (cnt+1))-      where cnt = fromIntegral (i-n)
− src/Data/Tuple/Extra.hs
@@ -1,7 +0,0 @@--- | Tuple utilities.--module Data.Tuple.Extra where---- | Swap tuple's elements.-swap :: (t1, t) -> (t, t1)-swap (a,b) = (b,a)