cookbook 1.3.0.0 → 1.5.0.0
raw patch · 9 files changed
+93/−15 lines, 9 files
Files
- Cookbook/Ingredients/Lists/Modify.hs +2/−0
- Cookbook/Ingredients/Lists/Remove.hs +26/−0
- Cookbook/Ingredients/Lists/Stats.hs +1/−0
- Cookbook/Project/Preprocess/Preprocess.hs +21/−0
- Cookbook/Recipes/Algorithm.hs +11/−0
- Cookbook/Recipes/DataStructures.hs +9/−0
- Cookbook/Recipes/Math.hs +21/−0
- Cookbook/Recipes/Text.hs +0/−13
- cookbook.cabal +2/−2
Cookbook/Ingredients/Lists/Modify.hs view
@@ -34,6 +34,7 @@ between :: (Eq a) => [a] -> (a,a) -> [a] between a (c,d) = Cnt.after (take (last $ Cm.positions a d) a) c +-- | Selectively parse a list based on the existance of a substring. linesBetween :: (Eq a) => [[a]] -> ([a],[a]) -> [[a]] linesBetween a (c,d) = tail $ Br.filterBreak (\e -> not $ Ac.contains e d) $ Br.removeBreak (\e -> not $ Ac.contains e c) a @@ -41,3 +42,4 @@ intersperse :: [a] -> a -> [a] intersperse [x] _ = [x] intersperse (x:xs) c = x:c : intersperse xs c+
+ Cookbook/Ingredients/Lists/Remove.hs view
@@ -0,0 +1,26 @@+--Cookbook.Ingredients.Lists.Remove+--Remove is an OGI for removing parts of lists.++{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+module Cookbook.Ingredients.Lists.Remove(Removable(..)) where++import Cookbook.Essential.Common as Cm+import Cookbook.Ingredients.Functional.Break as Br+import Cookbook.Ingredients.Lists.Modify as Md++class Removable list toRm where++ remove :: list -> toRm -> list++instance (Eq a) => Removable [a] a where+ remove x c = [y | y <- x, y /= c]++instance (Eq a) => Removable [a] [a] where+ remove [] _ = []+ remove x@(a:b) c = if take (length c) x == c then remove (restart x) c else a : remove b c+ where restart d = Cm.sub d (length c)++instance (Eq a) => Removable [a] (a,a) where+ remove [] _ = []+ remove (x:xs) (a,b) = if and [x == a, b `elem` xs] then remove (tail (Br.removeBreak (/=b) xs)) (a,b) else x : remove xs (a,b)
Cookbook/Ingredients/Lists/Stats.hs view
@@ -12,3 +12,4 @@ -- | Get the x amount of most frequent items in the list. mostFrequent :: (Eq a) => [a] -> Int -> [a] mostFrequent x c = take c $ Md.rev (As.assemble $ frequency x)+
+ Cookbook/Project/Preprocess/Preprocess.hs view
@@ -0,0 +1,21 @@+--Cookbook.Project.Preprocess.Preprocess+--A library for implementing preprocess syntax, as defined in the .std++module Cookbook.Project.Preprocess.Preprocess(makeParams,gPL) where++import qualified Cookbook.Ingredients.Lists.Replace as Rp+import qualified Cookbook.Ingredients.Lists.Modify as Md+import qualified Cookbook.Ingredients.Lists.Remove as Rm++import qualified Cookbook.Essential.Common as Cm++makeParams :: String -> [(String,String)]+makeParams x = (flip zip) (repeat lastPart) $ Md.splitOn firstPart '|'+ where (firstPart:lastPart:[]) = Md.splitOn x '_'++sanitize :: String -> String+sanitize x = Rm.remove x ('$','$')++gPL :: [String] -> [(String,String)]+gPL x = Cm.flt $ map makeParams sanitized+ where sanitized = Rm.remove (map (\c -> if (length c) > 3 then (sanitize c) else "") x) ""
+ Cookbook/Recipes/Algorithm.hs view
@@ -0,0 +1,11 @@+--Cookbook.Recipes.Algorithm+--Used for traversing data structures.+module Cookbook.Recipes.Algorithm(climb) where++import Cookbook.Recipes.DataStructures++climb :: (Tree a) -> a -> [a]+climb x c = case x of (Empty) -> [];+ (Branch a (Empty) b) -> a : climb b c+ (Branch a b (Empty)) -> a : climb b c+ (Branch a b d) -> a : climb b c ++ climb d c
+ Cookbook/Recipes/DataStructures.hs view
@@ -0,0 +1,9 @@+--Cookbook.Recipes.DataStructures+--Higher-level data structures for use in the rest of Cookbook.+module Cookbook.Recipes.DataStructures(Tree(..),) where++data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show)--add a "map" and "filter" function for Tree.++++
+ Cookbook/Recipes/Math.hs view
@@ -0,0 +1,21 @@+--Cookbook.Recipes.Math+--A library for mathematical formulas, parsing, and conversions.+module Cookbook.Recipes.Math(inc,dec,sqr,avg,stdev) where++--Simple, helper arithmetic functions.+inc :: (Num a) => a -> a+inc = (+1)++dec :: (Num a) => a -> a+dec x = x - 1 -- Negatives throw off currying++sqr :: (Num a) => a -> a+sqr x = (x*x)++avg :: (Fractional a) => [a] -> a+avg x = sum x / (realToFrac $ length x)++--Basic formulae+stdev :: (Fractional a, Floating a) => [a] -> a+stdev x = sqrt $ diffs / realToFrac (length x)+ where diffs = sum $ [sqr $ a - avg x| a <- x]
− Cookbook/Recipes/Text.hs
@@ -1,13 +0,0 @@---Cookbook.Recipes.Text---A library with the sole purpose of manipulating lists of strings.--module Cookbook.Recipes.Text(linesBetween) where--import qualified Cookbook.Essential.Continuous as Ct-import qualified Cookbook.Ingredients.Tupples.Look as Lk-import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Functional.Break as Br--linesBetween :: [String] -> (String,String) -> [String]-linesBetween x (c,d) = tail $ Br.filterBreak ( notContaining d) $ Br.removeBreak ( notContaining c) x- where notContaining e l = not $ l `Ac.contains` e
cookbook.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.3.0.0+version: 1.5.0.0 -- A short (one-line) description of the package. synopsis: A delicious set of interdependant libraries.@@ -48,7 +48,7 @@ library -- Modules exported by the library.- exposed-modules: Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Recipes.Text, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Scribe.Scribe, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace+ exposed-modules: Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Scribe.Scribe, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Remove, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm -- Modules included in this library but not exported. -- other-modules: