cookbook 2.2.0.0 → 2.2.1.0
raw patch · 7 files changed
+70/−14 lines, 7 files
Files
- Cookbook/Essential/Common.hs +6/−0
- Cookbook/Essential/Continuous.hs +9/−9
- Cookbook/Ingredients/Lists/Encompass.hs +37/−2
- Cookbook/Project/Quill/Quill.hs +1/−1
- Cookbook/Recipes/Cline.hs +8/−1
- Cookbook/Recipes/Sanitize.hs +8/−0
- cookbook.cabal +1/−1
Cookbook/Essential/Common.hs view
@@ -43,7 +43,13 @@ where rev [] = [] rev (x:xs) = rev xs ++ [x] +-- | After a certain number of an element, return the list. afterX :: (Eq a) => [a] -> a -> Int -> [a] afterX (x:xs) c t | t == 0 = x:xs | otherwise = if x == c then afterX xs c (pred t) else afterX xs c t++-- | Internal implementation of "intersperse".+iSp :: [a] -> a -> [a]+iSp [] _ = []+iSp (x:xs) c = ([x] ++ [c]) ++ iSp xs c
Cookbook/Essential/Continuous.hs view
@@ -21,13 +21,13 @@ -- | Classifies items that can be modified by either a list or item. class Continuous list part where- + -- | Returns all elements after part. after :: list -> part -> list -- | Returns all elements after part. before :: list -> part -> list- + -- | Removes part from the list. delete :: list -> part -> list @@ -35,7 +35,7 @@ after x c = tail $ Br.removeBreak (/=c) x before x c = Br.filterBreak (/=c) x delete x c = filter (/=c) x- + instance (Eq a) => Continuous [a] [a] where after [] _ = [] after x c = if Ac.isBefore x c then Cm.sub x (length c) else after (tail x) c@@ -48,7 +48,7 @@ -- | Classifies information which can be split by a tupple. class Splicable a b where- + -- | Removes everything between the tupple's parameters, including the parameters themselves. splice :: a -> b -> a @@ -60,19 +60,19 @@ -- | Classifies data which can be replaced. class Replacable list repls where- + -- | Replaces part of list. replace :: list -> repls -> list- + instance (Eq a) => Replacable [a] (a,a) where replace lst (on,tw) = map (\c -> if c == on then tw else c) lst- + instance (Eq a) => Replacable [a] [(a,a)] where replace x c = Cm.apply (map (flip replace) c) x- + instance (Eq a) => Replacable [a] ([a],[a]) where replace [] _ = []- replace lst (on,tw) + replace lst (on,tw) | take (length on) lst == on = tw ++ replace (Cm.sub lst (length on)) (on,tw) | otherwise = head lst : replace (tail lst) (on,tw)
Cookbook/Ingredients/Lists/Encompass.hs view
@@ -1,4 +1,9 @@ module Cookbook.Ingredients.Lists.Encompass where++import qualified Cookbook.Essential.Continuous as Ct+import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Ingredients.Functional.Break as Br+ {- | Module : Cookbook.Ingredients.Lists.Encompass Copyright : (c) 2014 by Nate Pisarski@@ -8,7 +13,6 @@ Portability : Portable (Cookbook) Encompass is a library for parsing that is stringent on scope. It supports scope monitoring on single sets of single elements in a list, but it does not need to be a string. -}-import qualified Cookbook.Essential.Continuous as Ct -- | Get the entire section of a list contained within the scope delimited by the parameters, even sub-scopes. encompassing :: (Eq a) => [a] -> (a,a) -> [a]@@ -39,8 +43,39 @@ | not $ f `elem` e && g `elem` e = [e] | otherwise = beforeEncompassing e (f,g) : splitEncompassing (afterEncompassing e (f,g)) (f,g) +-- | There is a long story behind this function, and why it sucks. See ENN1 in the source.+notEncompassedSplit :: (Eq a) => [a] -> (a,a) -> a -> [[a]]+notEncompassedSplit [] _ _ = [] -- "b{c,d},e,{f:g,e:h}"+notEncompassedSplit ls (sp1,sp2) sp = toGaps $ helper ls 0+ where+ helper [] _ = []+ helper (x:xs) c+ | x == sp1 && c >= 0 = (sp1: encompassing (x:xs) (sp1,sp2)) : helper (afterEncompassing xs (sp1,sp2)) (c + 1)+ | x == sp2 && c <= 0 = [x] : helper xs (c - 1)+ | x == sp1 = [x] : helper xs (c+1)+ | x == sp2 = [x] : helper xs (c - 1)+ | x == sp && c > 0 = [x] : helper xs c+ | x == sp && c <= 0 = [] : helper xs c+ | otherwise = [x] : helper xs c++toGaps :: (Eq a) => [[a]] -> [[a]]+toGaps [] = []+toGaps x+ | [] `notElem` x = [Cm.flt x]+ | otherwise = (Cm.flt (Br.filterBreak (\c -> c /= []) x)) : (toGaps $ tail (Br.removeBreak (\c -> c /= []) x))+ -- | Returns all of the elements inside of a scope. gatherEncompassing :: (Eq a) => [a] -> (a,a) -> [[a]]-gatherEncompassing a (b,c)+gatherEncompassing a (b,c) | not $ b `elem` a && c `elem` a = [] | otherwise = encompassing a (b,c) : gatherEncompassing (afterEncompassing a (b,c)) (b,c)++-- [ENN1]+-- This function is terrible. Bloody AWFUL. So, why include it? Because it works.+-- the implementation of the function is hard to rework, so unfortunately it doesn't+-- get much better than this. I've tried rereading it time and time again, and the+-- details of how it works confuse me. Prior to making the function, I spent+-- more than a month thinking about how it should work. After that didn't work+-- I began to change variables and behaviors in a fit of rage, and it started+-- to work. And don't question the helper function either. This is as good+-- as it gets, ladies and gentlemen.
Cookbook/Project/Quill/Quill.hs view
@@ -62,7 +62,7 @@ -- | Removes an entire table from the database by name. removeTable :: [(String,[(String,String)])] -> String -> [(String,[(String,String)])]-removeTable x c = [e | e@(d,_) <- x, d /= c]+removeTable x c = [e | e@(d,_) <- x, d /= c] -- WOAH what does this do? -- | Removes a particular item from a table within a database. removeItem :: [(String,[(String,String)])] -> (String,String) -> [(String,[(String,String)])]
Cookbook/Recipes/Cline.hs view
@@ -1,9 +1,10 @@-module Cookbook.Recipes.Cline(parse,Cline(..),clineExtract) where+module Cookbook.Recipes.Cline(parse,Cline(..),clineExtract,clArg) where import qualified Cookbook.Essential.Continuous as Ct import qualified Cookbook.Essential.Common as Cm import qualified Cookbook.Ingredients.Lists.Modify as Md import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Recipes.Sanitize as Sn {- | Module : Cookbook.Recipes.Cline@@ -39,3 +40,9 @@ -- | Parse a flat string into a list of Clines. parse :: String -> [Cline] parse = clineExtract . (`Md.splitOn` ' ')++-- Helpers++-- | Cleans a command line argument. If it's not a number, it will add a couple of dashes in front of it.+clArg :: String -> String+clArg x = if '-' `notElem` x && Sn.notNumeral x then ("--" ++ x) else x
Cookbook/Recipes/Sanitize.hs view
@@ -57,3 +57,11 @@ -- | Removes all "symbols" from a string rmsymbols :: String -> String rmsymbols = (`blacklist` ['\\'..'`'])++-- | Check to see if the string is a non-numeral+notNumeral :: String -> Bool+notNumeral x = all (\c -> c `elem` ['A'..'z']) x++-- | Check to see if the string is numeral.+numeral :: String -> Bool+numeral x = all (\c -> c `notElem` ['A'..'z']) x
cookbook.cabal view
@@ -3,7 +3,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 2.2.0.0+version: 2.2.1.0 synopsis: Tiered general-purpose libraries with domain-specific applications. description: Cookbook is a line of libraries covering a wide variety of Haskell applications. Every application that I make, I add its functions to Cookbook, turning Cookbook into an all-encompassing general-purpose library over time. The claim-to-fame for the library is its use of overloaded typeclasses, called "Continuities". license: BSD3