packages feed

hx (empty) → 0.1

raw patch · 4 files changed

+106/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,18 @@+Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the "Software"),+to deal in the Software without restriction, including without limitation+the rights to use, copy, modify, merge, publish, distribute, sublicense,+and/or sell copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER+DEALINGS IN THE SOFTWARE.+
+ Setup.hs view
@@ -0,0 +1,4 @@+import Distribution.Simple++main = defaultMain+
+ hx.cabal view
@@ -0,0 +1,25 @@+Name:           hx+Version:        0.1+Synopsis:       Utility functions that some may feel are missing from Prelude and base.+Description:    Utility functions that some may feel are missing from Prelude and base.+                .+                Some functions are taken from the package @hinduce-missingh@, which was+                written by Robert Hensing and published under the BSD 3-clause license.+                +License:        MIT+License-File:   LICENSE+Author:         Julian Fleischer <julian.fleischer@fu-berlin.de>+Maintainer:     Julian Fleischer <julian.fleischer@fu-berlin.de>+Build-Type:     Simple+Cabal-Version:  >= 1.8+Category:       Utilities+Stability:      provisional+++Library+    Exposed-Modules:    Haskell.X++    Build-Depends:      base >= 4 && < 5+    Hs-Source-Dirs:     src++
+ src/Haskell/X.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE Haskell2010 #-}+{-# OPTIONS -Wall #-}++module Haskell.X where++import Data.List+import Data.Ord+import Control.Arrow++++-- | Apply a function exhaustively.+exhaustively :: Eq a => (a -> a) -> a -> a+exhaustively = exhaustivelyBy (==)++-- | Apply a function exhaustively.+exhaustivelyBy :: (a -> a -> Bool) -> (a -> a) -> a -> a+exhaustivelyBy predicate func dat = case predicate dat result of+    True -> result+    False -> exhaustivelyBy predicate func result+  where result = func dat++-- | Apply a monad function exhaustively.+exhaustivelyM :: (Eq a, Monad m) => (a -> m a) -> a -> m a+exhaustivelyM = exhaustivelyByM (==)++-- | Apply a monad function exhaustively.+exhaustivelyByM :: Monad m => (a -> a -> Bool) -> (a -> m a) -> a -> m a+exhaustivelyByM predicate func dat = do+    result <- func dat+    case predicate dat result of+        True -> return result+        False -> exhaustivelyByM predicate func result++-- | Sort a list and leave out duplicates. Like @nub . sort@ but faster.+uniqSort :: (Ord a) => [a] -> [a]+uniqSort = map head . group . sort++-- | Sort, then group+aggregateBy :: (a -> a -> Ordering) -> [a] -> [[a]]+aggregateBy x = groupBy (\a b -> x a b == EQ) . sortBy x++-- | Sort, then group+aggregate :: (Ord a) => [a] -> [[a]]+aggregate = aggregateBy compare++-- | Aggregate an association list, such that keys become unique.+--+-- (c) +aggregateAL :: (Ord a) => [(a,b)] -> [(a,[b])]+aggregateAL = map (fst . head &&& map snd) . aggregateBy (comparing fst)++-- | Replace all occurences of a specific thing in a list of things another thing. +tr :: Eq a => a -> a -> [a] -> [a]+tr n r (x:xs)+    | x == n = r : tr n r xs+    | otherwise = x : tr n r xs+tr _ _ [] = []+