not-in-base (empty) → 0.1.1
raw patch · 6 files changed
+266/−0 lines, 6 filesdep +basesetup-changed
Dependencies added: base
Files
- COPYING.txt +14/−0
- Setup.lhs +6/−0
- not-in-base.cabal +46/−0
- src/NIB/List.hs +33/−0
- src/NIB/Pointfree.hs +90/−0
- src/NIB/String.hs +77/−0
+ COPYING.txt view
@@ -0,0 +1,14 @@+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE+ Version 2, December 2004++ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>++ Everyone is permitted to copy and distribute verbatim or modified+ copies of this license document, and changing it is allowed as long+ as the name is changed.++ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. You just DO WHAT THE FUCK YOU WANT TO.+
+ Setup.lhs view
@@ -0,0 +1,6 @@+#!/usr/bin/runhaskell +> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMain+
+ not-in-base.cabal view
@@ -0,0 +1,46 @@+name: not-in-base+version: 0.1.1+cabal-version: -any+build-type: Simple+license: OtherLicense+license-file: "COPYING.txt"+copyright:+maintainer: Oscar Finnsson+build-depends: base >= 4 && < 5+stability:+homepage: http://github.com/finnsson/not-in-base+package-url:+bug-reports:+synopsis: Useful utility functions that only depend on base. +description: Useful utility functions that only depend on base.+category: Utility+author: Oscar Finnsson+tested-with: GHC -any+data-files:+data-dir: ""+extra-source-files:+extra-tmp-files:+exposed-modules: NIB.String, NIB.Pointfree, NIB.List+exposed: True+buildable: True+build-tools:+cpp-options:+cc-options:+ld-options:+pkgconfig-depends:+frameworks:+c-sources:+extensions:+extra-libraries:+extra-lib-dirs:+includes:+install-includes:+include-dirs:+hs-source-dirs: src+other-modules:+ghc-prof-options:+ghc-shared-options:+ghc-options:+hugs-options:+nhc98-options:+jhc-options:
+ src/NIB/List.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE UndecidableInstances, OverlappingInstances, FlexibleInstances, TypeSynonymInstances+ #-}++module NIB.List where++import Data.Char+import Data.Maybe+import Data.List+import Control.Monad+++-- | Splits a list @x@ of @a@ into a list of lists of @a@ at every @c@.+--+-- > "splitBy "foo,bar" "',' == ["foo","bar"] ' +splitBy :: (Eq a) => a -> [a] -> [[a]]+splitBy _ [] = [[]]+splitBy c x = if fst p == [] then [snd p] else fst p : splitBy c ( snd p )+ where p = break (== c) x++-- | Trims every element satisfying @c@ from the beginning or end of the list.+--+-- > trim (==' ') " foo " == "foo"+trim :: (a -> Bool) -> [a] -> [a]+trim c = reverse . dropWhile c . reverse . dropWhile c++-- | Convert first element in list+--+-- > convertFirst (toUpper) "fO0" == "FO0"+convertFirst :: (a -> a) -> [a] -> [a]+convertFirst _ [] = []+convertFirst f (x:xs) = f x:xs++
+ src/NIB/Pointfree.hs view
@@ -0,0 +1,90 @@+{-# LANGUAGE UndecidableInstances, OverlappingInstances, FlexibleInstances, TypeSynonymInstances+ #-}++module NIB.Pointfree where++import Data.Char+import Data.Maybe+import Data.List+import Control.Monad++-- \ Tuple functions++fst3 :: (a,b,c) -> a+fst3 (a,b,c) = a++snd3 :: (a,b,c) -> b+snd3 (a,b,c) = b++trd3 :: (a,b,c) -> c+trd3 (a,b,c) = c+trd (a,b,c) = c+++-- | Lambdifies a function. See '(||*)' and '(&&*)' for uses of 'lambdify'.+-- | Used in order to make operators capable of operating on functions that later on+-- | are supplied some value that all functions operate on.+--+-- > (+*) = lambdify (+)+-- > fourTwo = (*4) +* (*2)+-- > 42 == fourTwo 7+lambdify :: (x -> y -> z) -> (t -> x) -> (t -> y) -> t -> z+lambdify f a b x = f (a x) (b x)++-- | Lambdifies '(||)'.+--+-- > isBlankOrCommaChecker = (==' ') ||* (==',')+-- > isBlankOrComma = isBlankOrCommaChecker 'j'+(||*) :: (a -> Bool) -> (a -> Bool) -> a -> Bool+(||*) = lambdify (||)++-- | Lambdifies '(&&)'.+--+-- > isInRangeChecker = (>9) &&* (<30)+-- > isInRange = isInRangeChecker 17+(&&*) :: (a -> Bool) -> (a -> Bool) -> a -> Bool+(&&*) = lambdify (&&)++-- | 2-point-free operator. Similar to '.', but where+-- | the second function takes two (2) arguments instead of one (1).+--+-- > multAndSquare (^2) .^.. (*)+-- > 36 == multAndSqare 2 3+(^..) :: (c -> d) -> (a -> b -> c) -> a -> b-> d+(f ^.. g) a = f . g a++-- | 3-point-free operator. See '(^..)'.+(^...) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e+(f ^...g ) a b = f . g a b++-- | Split a 2-tuple 'x' into a 2-stack and pass it to 'f'.+-- | The same as uncurry.+(..%) :: (a -> b -> c) -> (a,b) -> c+(..%) = uncurry ++(..%..) :: (c->d->e) -> (a->b->(c,d)) -> a -> b -> e+(f ..%.. g) a b = f ..% g a b++-- | Split a 3-tuple 'x' into a 3-stack and pass it to 'f'.+(...%) :: (a -> b -> c -> d) -> (a,b,c) -> d+(...%) f x = f (fst3 x) (snd3 x) (trd3 x)+++-- | Pipes a monadic return through a non-monadic transformation function.+-- | liftM with arguments flipped.+--+-- > readIO >>* toUpper+(>>*) :: Monad m => m a -> (a -> b) -> m b+(>>*) v f = liftM f v -- v >>= (return . f)++-- > f = ((+) 2, (*) 3)+-- > x = 7+-- > r = f ..@ x+-- +-- | gives `(9, 21)`, i.e. `(2 + 9, 3 * 7)`.+(..@) :: (a -> b, a -> c) -> a -> (b,c) +f ..@ x = (fst f x, snd f x)++-- | Same as `..@`, but with a 3-tuple. +(...@) :: (a -> b, a -> c, a -> d) -> a -> (b,c,d)+f ...@ x = (fst3 f x, snd3 f x, trd3 f x)
+ src/NIB/String.hs view
@@ -0,0 +1,77 @@+-- {-# OPTIONS_GHC -fglasgow-exts -, +-- +-- #-}+{-# LANGUAGE UndecidableInstances, OverlappingInstances, FlexibleInstances, TypeSynonymInstances+ #-}+{-|+ Contains useful generic functions not found elsewhere.+++-}+module NIB.String where++import Data.Char++import NIB.List+import NIB.Pointfree+++-- \ String functions++-- \ ToString type class as found on stackoverflow (Porges answer at+-- http://stackoverflow.com/questions/968198/haskell-show-screwed-up)+-- Expanded with instance ToString Char.+class ToString a where+ toString :: a -> String++instance ToString String where+ toString = id++instance ToString Char where+ toString c = [c]++instance Show a => ToString a where+ toString = show++++-- | Remove all line breaks in a string+--+-- > "testtest" == removeBreak "test\n\rtest\r"+removeBreak :: String -> String+removeBreak = filter ((/= '\r') &&* (/= '\n'))++-- | Convert first character in String to lower.+--+-- > lowerFirst "Foo" == "foo"+-- > lowerFirst "BaR" == "baR"+-- > lowerFirst "g0O" == "g0O".'+lowerFirst :: String -> String+lowerFirst = convertFirst toLower++-- | Convert first character in String to upper.+--+-- > upperFirst "foo" == "Foo"+-- > upperFirst "bAr" == "BAr"+-- > upperFirst "G0O" == "G0O".'+upperFirst :: String -> String+upperFirst = convertFirst toUpper++-- | Convert every space (' ') in a string to a blank ('_') instead. +--+-- > spaceToBlank " " == "_"+-- > spaceToBlank " foo " == "_foo__"+-- > spaceToBlank "b a r" == "b_a_r"+spaceToBlank :: String -> String+spaceToBlank "" = ""+spaceToBlank (x:xs) = (if x == ' ' then '_' else x) : spaceToBlank xs++++-- | Trims whitespace from the beginning or end.+--+-- > trimWs " foo " == "foo"+trimWs :: String -> String+trimWs = trim (==' ')++