packages feed

extra 1.6.2 → 1.6.3

raw patch · 6 files changed

+45/−6 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Typeable.Extra: data (:~:) k (a :: k) (b :: k) :: forall k. k -> k -> *
- Data.Typeable.Extra: data Proxy k (t :: k) :: forall k. k -> *
- Extra: data (:~:) k (a :: k) (b :: k) :: forall k. k -> k -> *
- Extra: data Proxy k (t :: k) :: forall k. k -> *
+ Data.List.Extra: maximumOn :: Ord b => (a -> b) -> [a] -> a
+ Data.List.Extra: minimumOn :: Ord b => (a -> b) -> [a] -> a
+ Data.List.Extra: nubSort :: Ord a => [a] -> [a]
+ Data.List.Extra: nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
+ Data.List.Extra: nubSortOn :: Ord b => (a -> b) -> [a] -> [a]
+ Data.Typeable.Extra: data Proxy k (t :: k) :: forall k. () => k -> *
+ Extra: data Proxy k (t :: k) :: forall k. () => k -> *
+ Extra: maximumOn :: Ord b => (a -> b) -> [a] -> a
+ Extra: minimumOn :: Ord b => (a -> b) -> [a] -> a
+ Extra: nubSort :: Ord a => [a] -> [a]
+ Extra: nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
+ Extra: nubSortOn :: Ord b => (a -> b) -> [a] -> [a]
- Control.Concurrent.Extra: forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
+ Control.Concurrent.Extra: forkFinally :: () => IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
- Control.Exception.Extra: errorWithoutStackTrace :: [Char] -> a
+ Control.Exception.Extra: errorWithoutStackTrace :: () => [Char] -> a
- Data.Either.Extra: fromLeft :: a -> Either a b -> a
+ Data.Either.Extra: fromLeft :: () => a -> Either a b -> a
- Data.Either.Extra: fromRight :: b -> Either a b -> b
+ Data.Either.Extra: fromRight :: () => b -> Either a b -> b
- Data.Either.Extra: isLeft :: Either a b -> Bool
+ Data.Either.Extra: isLeft :: () => Either a b -> Bool
- Data.Either.Extra: isRight :: Either a b -> Bool
+ Data.Either.Extra: isRight :: () => Either a b -> Bool
- Data.IORef.Extra: atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b
+ Data.IORef.Extra: atomicModifyIORef' :: () => IORef a -> (a -> (a, b)) -> IO b
- Data.IORef.Extra: atomicWriteIORef :: IORef a -> a -> IO ()
+ Data.IORef.Extra: atomicWriteIORef :: () => IORef a -> a -> IO ()
- Data.IORef.Extra: modifyIORef' :: IORef a -> (a -> a) -> IO ()
+ Data.IORef.Extra: modifyIORef' :: () => IORef a -> (a -> a) -> IO ()
- Data.List.Extra: dropWhileEnd :: (a -> Bool) -> [a] -> [a]
+ Data.List.Extra: dropWhileEnd :: () => (a -> Bool) -> [a] -> [a]
- Data.List.Extra: uncons :: [a] -> Maybe (a, [a])
+ Data.List.Extra: uncons :: () => [a] -> Maybe (a, [a])
- Extra: atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> IO b
+ Extra: atomicModifyIORef' :: () => IORef a -> (a -> (a, b)) -> IO b
- Extra: atomicWriteIORef :: IORef a -> a -> IO ()
+ Extra: atomicWriteIORef :: () => IORef a -> a -> IO ()
- Extra: dropWhileEnd :: (a -> Bool) -> [a] -> [a]
+ Extra: dropWhileEnd :: () => (a -> Bool) -> [a] -> [a]
- Extra: errorWithoutStackTrace :: [Char] -> a
+ Extra: errorWithoutStackTrace :: () => [Char] -> a
- Extra: forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
+ Extra: forkFinally :: () => IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
- Extra: fromLeft :: a -> Either a b -> a
+ Extra: fromLeft :: () => a -> Either a b -> a
- Extra: fromRight :: b -> Either a b -> b
+ Extra: fromRight :: () => b -> Either a b -> b
- Extra: isLeft :: Either a b -> Bool
+ Extra: isLeft :: () => Either a b -> Bool
- Extra: isRight :: Either a b -> Bool
+ Extra: isRight :: () => Either a b -> Bool
- Extra: lookupEnv :: String -> IO (Maybe String)
+ Extra: lookupEnv :: String -> IO Maybe String
- Extra: modifyIORef' :: IORef a -> (a -> a) -> IO ()
+ Extra: modifyIORef' :: () => IORef a -> (a -> a) -> IO ()
- Extra: uncons :: [a] -> Maybe (a, [a])
+ Extra: uncons :: () => [a] -> Maybe (a, [a])
- Extra: withCurrentDirectory :: FilePath -> IO a -> IO a
+ Extra: withCurrentDirectory :: () => FilePath -> IO a -> IO a
- System.Environment.Extra: lookupEnv :: String -> IO (Maybe String)
+ System.Environment.Extra: lookupEnv :: String -> IO Maybe String

Files

CHANGES.txt view
@@ -1,5 +1,8 @@ Changelog for Extra +1.6.3, released 2018-01-26+    Add maximumOn and minimumOn+    #31, add nubSort, nubSortBy and nubSortOn 1.6.2, released 2017-12-07     Mark the partial functions with Partial     Add Partial constraint
LICENSE view
@@ -1,4 +1,4 @@-Copyright Neil Mitchell 2014-2017.+Copyright Neil Mitchell 2014-2018. All rights reserved.  Redistribution and use in source and binary forms, with or without
extra.cabal view
@@ -1,13 +1,13 @@ cabal-version:      >= 1.18 build-type:         Simple name:               extra-version:            1.6.2+version:            1.6.3 license:            BSD3 license-file:       LICENSE category:           Development author:             Neil Mitchell <ndmitchell@gmail.com> maintainer:         Neil Mitchell <ndmitchell@gmail.com>-copyright:          Neil Mitchell 2014-2017+copyright:          Neil Mitchell 2014-2018 synopsis:           Extra functions I use. description:     A library of extra functions for the standard Haskell libraries. Most functions are simple additions, filling out missing functionality. A few functions are available in later versions of GHC, but this package makes them available back to GHC 7.2.@@ -15,7 +15,7 @@     The module "Extra" documents all functions provided by this library. Modules such as "Data.List.Extra" provide extra functions over "Data.List" and also reexport "Data.List". Users are recommended to replace "Data.List" imports with "Data.List.Extra" if they need the extra functionality. homepage:           https://github.com/ndmitchell/extra#readme bug-reports:        https://github.com/ndmitchell/extra/issues-tested-with:        GHC==8.2.1, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2+tested-with:        GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2  extra-doc-files:     CHANGES.txt
src/Data/List/Extra.hs view
@@ -9,7 +9,7 @@     module Data.List,     -- * String operations     lower, upper, trim, trimStart, trimEnd, word1, line1,-    -- * Splitting    +    -- * Splitting     dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd,     dropWhileEnd, dropWhileEnd', takeWhileEnd,     stripSuffix, stripInfix, stripInfixEnd,@@ -21,6 +21,8 @@     groupSort, groupSortOn, groupSortBy,     nubOrd, nubOrdBy, nubOrdOn,     nubOn, groupOn, sortOn,+    nubSort, nubSortBy, nubSortOn,+    maximumOn, minimumOn,     disjoint, allSame, anySame,     repeatedly, for, firstJust,     concatUnzip, concatUnzip3,@@ -296,7 +298,14 @@ nubOn :: Eq b => (a -> b) -> [a] -> [a] nubOn f = map snd . nubBy ((==) `on` fst) . map (\x -> let y = f x in y `seq` (y, x)) +-- | A version of 'maximum' where the comparison is done on some extracted value.+maximumOn :: Ord b => (a -> b) -> [a] -> a+maximumOn f = maximumBy (compare `on` f) +-- | A version of 'minimum' where the comparison is done on some extracted value.+minimumOn :: Ord b => (a -> b) -> [a] -> a+minimumOn f = minimumBy (compare `on` f)+ -- | A combination of 'group' and 'sort'. -- -- > groupSort [(1,'t'),(3,'t'),(2,'e'),(2,'s')] == [(1,"t"),(2,"es"),(3,"t")]@@ -547,6 +556,29 @@ chunksOf i xs | i <= 0 = error $ "chunksOf, number must be positive, got " ++ show i chunksOf i xs = repeatedly (splitAt i) xs ++-- | /O(n log n)/. The 'nubSort' function sorts and removes duplicate elements from a list.+-- In particular, it keeps only the first occurrence of each element.+--+-- > nubSort "this is a test" == " aehist"+-- > \xs -> nubSort xs == nub (sort xs)+nubSort :: Ord a => [a] -> [a]+nubSort = nubSortBy compare++-- | A version of 'nubSort' which operates on a portion of the value.+--+-- > nubSortOn length ["a","test","of","this"] == ["a","of","test"]+nubSortOn :: Ord b => (a -> b) -> [a] -> [a]+nubSortOn f = nubSortBy (compare `on` f)++-- | A version of 'nubSort' with a custom predicate.+--+-- > nubSortBy (compare `on` length) ["a","test","of","this"] == ["a","of","test"]+nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]+nubSortBy cmp = f . sortBy cmp+    where f (x1:x2:xs) | cmp x1 x2 == EQ = f (x1:xs)+          f (x:xs) = x : f xs+          f [] = []  -- | /O(n log n)/. The 'nubOrd' function removes duplicate elements from a list. -- In particular, it keeps only the first occurrence of each element.
src/Extra.hs view
@@ -23,7 +23,7 @@     modifyIORef', writeIORef', atomicModifyIORef', atomicWriteIORef, atomicWriteIORef',     -- * Data.List.Extra     -- | Extra functions available in @"Data.List.Extra"@.-    lower, upper, trim, trimStart, trimEnd, word1, line1, dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd, dropWhileEnd, dropWhileEnd', takeWhileEnd, stripSuffix, stripInfix, stripInfixEnd, wordsBy, linesBy, breakOn, breakOnEnd, splitOn, split, chunksOf, list, uncons, unsnoc, cons, snoc, drop1, mconcatMap, groupSort, groupSortOn, groupSortBy, nubOrd, nubOrdBy, nubOrdOn, nubOn, groupOn, sortOn, disjoint, allSame, anySame, repeatedly, for, firstJust, concatUnzip, concatUnzip3, zipFrom, zipWithFrom, replace, merge, mergeBy,+    lower, upper, trim, trimStart, trimEnd, word1, line1, dropEnd, takeEnd, splitAtEnd, breakEnd, spanEnd, dropWhileEnd, dropWhileEnd', takeWhileEnd, stripSuffix, stripInfix, stripInfixEnd, wordsBy, linesBy, breakOn, breakOnEnd, splitOn, split, chunksOf, list, uncons, unsnoc, cons, snoc, drop1, mconcatMap, groupSort, groupSortOn, groupSortBy, nubOrd, nubOrdBy, nubOrdOn, nubOn, groupOn, sortOn, nubSort, nubSortBy, nubSortOn, maximumOn, minimumOn, disjoint, allSame, anySame, repeatedly, for, firstJust, concatUnzip, concatUnzip3, zipFrom, zipWithFrom, replace, merge, mergeBy,     -- * Data.Tuple.Extra     -- | Extra functions available in @"Data.Tuple.Extra"@.     first, second, (***), (&&&), dupe, both, fst3, snd3, thd3,
test/TestGen.hs view
@@ -194,6 +194,10 @@     testGen "chunksOf 3 \"mytest\"  == [\"myt\",\"est\"]" $ chunksOf 3 "mytest"  == ["myt","est"]     testGen "chunksOf 8 \"\"        == []" $ chunksOf 8 ""        == []     testGen "chunksOf 0 \"test\"    == undefined" $ erroneous $ chunksOf 0 "test"+    testGen "nubSort \"this is a test\" == \" aehist\"" $ nubSort "this is a test" == " aehist"+    testGen "\\xs -> nubSort xs == nub (sort xs)" $ \xs -> nubSort xs == nub (sort xs)+    testGen "nubSortOn length [\"a\",\"test\",\"of\",\"this\"] == [\"a\",\"of\",\"test\"]" $ nubSortOn length ["a","test","of","this"] == ["a","of","test"]+    testGen "nubSortBy (compare `on` length) [\"a\",\"test\",\"of\",\"this\"] == [\"a\",\"of\",\"test\"]" $ nubSortBy (compare `on` length) ["a","test","of","this"] == ["a","of","test"]     testGen "nubOrd \"this is a test\" == \"this ae\"" $ nubOrd "this is a test" == "this ae"     testGen "nubOrd (take 4 (\"this\" ++ undefined)) == \"this\"" $ nubOrd (take 4 ("this" ++ undefined)) == "this"     testGen "\\xs -> nubOrd xs == nub xs" $ \xs -> nubOrd xs == nub xs