packages feed

cookbook 0.1.1.0 → 0.1.3.0

raw patch · 4 files changed

+28/−9 lines, 4 files

Files

Cookbook/Common.hs view
@@ -1,4 +1,4 @@-module Cookbook.Common(sub,positions,pos) where+module Cookbook.Common(sub,positions,pos,apply) where  --Cut a list off at a certain point --sub [1,2,3] 1 -> [2 3]@@ -23,6 +23,11 @@ pos :: (Eq a) => [a] -> a -> Int pos x c | c `notElem` x = -1 pos x c = let ans = positions x c in ((if (length ans) > 1 then (head . tail) else head) ans)-          ++--Apply a list of functions to one value.+-- | Apply a list of functiosn to one value, using the result from the function beforehand.+apply :: [(a -> a)] -> a -> a+apply [] c = c+apply (f:fs) c = apply fs (f c)  
Cookbook/Continuous.hs view
@@ -5,6 +5,7 @@  import Cookbook.Common import Cookbook.Ingredients.Functional.Break+import Cookbook.Ingredients.Lists.Access  -- | Continuous provides an interface for function overloading. Everything automatically qualifies to be a constrained by class continuous, so no anotation is required in any type signatures. class Continuous list part where@@ -14,10 +15,14 @@    -- | Before returns a sub-list before either the first occurence of an element or sublist.   before :: list -> part -> list-  ++-- | Remove an item from a list, when used on an element, it works the same as rm.+  delete :: list -> part -> list+ instance (Eq a) => Continuous [a] a where-  after x c = tail $ removeBreak (/=c) x-  before x c = filterBreak (/=c) x+  after x c     = tail $ removeBreak (/=c) x+  before x c  = filterBreak (/=c) x+  delete x c  = filter (/= c) x    instance (Eq a) => Continuous [a] [a] where   after [] _ = []@@ -29,3 +34,8 @@   before x c     | take (length c) x == c = []     | otherwise = (head x) : before (tail x) c++  delete [] _ = []+  delete x c+    | not (x `contains` c) = x+    | otherwise = (before x c) ++ delete (after x c) c
Cookbook/Ingredients/Lists/Modify.hs view
@@ -1,6 +1,5 @@-{-# LANGUAGE FlexibleContexts #-} module Cookbook.Ingredients.Lists.Modify(-rev,rm,splitOn,snipe) where+rev,rm,splitOn,snipe,insert) where  import qualified Cookbook.Continuous as Cnt import qualified Cookbook.Common as Com@@ -16,9 +15,14 @@ rm x c = filter (/=c) x  -- | Create sub-lists based on a delimeter. The string 'joe,joe1,joe2' splitOn ',' would return a list of the three joes.-splitOn :: (Cnt.Continuous [a] a, Eq a) => [a] -> a -> [[a]]+splitOn :: (Eq a) => [a] -> a -> [[a]] splitOn [] _ = [] splitOn x c = if (c `notElem` x) then [x] else (Cnt.before x c) : splitOn (Cnt.after x c) c +-- | Change a location in a list with an element. snipe :: (Eq a) => [a] -> (a,Int) -> [a] snipe x (t,c) = (take c x) ++ [t] ++ (Com.sub x (c + 1))++-- | Snipe, workable with lists and does not delete information.+insert :: (Eq a) => [a] -> ([a],Int) -> [a]+insert x (t,c) = (take c x) ++ t ++ (Com.sub x c)
cookbook.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.1.0+version:             0.1.3.0  -- A short (one-line) description of the package. synopsis:            An independent library of common haskell operations.