packages feed

setdown 0.1.0.3 → 0.1.0.4

raw patch · 5 files changed

+46/−49 lines, 5 filesdep ~containers

Dependency ranges changed: containers

Files

ExternalSort.hs view
@@ -1,6 +1,6 @@-module ExternalSort -   ( extractAndSortFiles -   , extractAndSortFile +module ExternalSort+   ( extractAndSortFiles+   , extractAndSortFile    , splitSortAndMerge    ) where @@ -12,7 +12,6 @@ import Control.Monad (forM) import System.FilePath ((</>)) import Control.Arrow (second)-import Control.Applicative import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.IO as T @@ -35,7 +34,7 @@    mapM simpleFileSort splits  simpleFileSort :: FilePath -> IO FilePath-simpleFileSort fp = do +simpleFileSort fp = do    T.writeFile sfp . T.unlines . sort . T.lines =<< T.readFile fp    return sfp    where
Main.hs view
@@ -7,7 +7,6 @@ import           System.Console.CmdArgs import           System.Exit -import           Control.Applicative import           Control.Monad          (filterM, forM_, unless) import           Data.List              (intersperse, isSuffixOf, partition) import           Data.Maybe             (fromMaybe)
PerformOperations.hs view
@@ -1,30 +1,29 @@ module PerformOperations (runSimpleDefinitions) where -import Control.Arrow (first)-import Control.Applicative-import Control.Monad.State.Lazy-import Context-import SetData-import qualified Data.Text.Lazy as T-import qualified Data.Text.Lazy.IO as T-import qualified Data.Map as M-import qualified Data.UUID.V4 as UUID+import           Context+import           Control.Arrow            (first)+import           Control.Monad.State.Lazy+import qualified Data.Map                 as M+import qualified Data.Text.Lazy           as T+import qualified Data.Text.Lazy.IO        as T+import qualified Data.UUID.V4             as UUID+import           SetData  data ComputeState = CS    { expressionToFile :: M.Map BaseExpression FilePath-   , definitionMap :: M.Map Identifier SimpleDefinition-   , csContext :: Context+   , definitionMap    :: M.Map Identifier SimpleDefinition+   , csContext        :: Context    }  runSimpleDefinitions :: Context -> SimpleDefinitions -> [(FilePath, FilePath)] -> IO [(SimpleDefinition, FilePath)] runSimpleDefinitions context defs sortedFileMapping = fst <$> runStateT (computeSimpleDefinitions defs) cs    where       cs = CS-         { expressionToFile = setupExpressionsToFile sortedFileMapping +         { expressionToFile = setupExpressionsToFile sortedFileMapping          , definitionMap = toDefinitionMap defs          , csContext = context          }-      + toDefinitionMap :: SimpleDefinitions -> M.Map Identifier SimpleDefinition toDefinitionMap = M.fromList . fmap (\x -> (sdId x, x)) @@ -54,7 +53,7 @@    return resultFile  computeBaseExpression :: BaseExpression -> StateT ComputeState IO FilePath-computeBaseExpression be@(BaseFileExpression fp) = do +computeBaseExpression be@(BaseFileExpression fp) = do    expressionMap <- expressionToFile <$> get    case M.lookup be expressionMap of       Just sortedFile -> return sortedFile@@ -74,25 +73,25 @@  fileSetOperation :: Context -> Operator -> FilePath -> FilePath -> IO FilePath fileSetOperation ctx ot leftFp rightFp = do-   leftContents <- T.lines <$> T.readFile leftFp -   rightContents <- T.lines <$> T.readFile rightFp -   let mergedContents = linesSetOperation (operatorTools ot) leftContents rightContents -   randomFilename <- randomFilenameInOutput ctx-   T.writeFile randomFilename . T.unlines $ mergedContents-   return randomFilename-   +   leftContents <- T.lines <$> T.readFile leftFp+   rightContents <- T.lines <$> T.readFile rightFp+   let mergedContents = linesSetOperation (operatorTools ot) leftContents rightContents+   outputFilename <- randomFilenameInOutput ctx+   T.writeFile outputFilename . T.unlines $ mergedContents+   return outputFilename+ randomFilenameInOutput :: Context -> IO FilePath randomFilenameInOutput ctx = inOutput ctx . show <$> UUID.nextRandom  linesSetOperation :: OperatorTools T.Text -> [T.Text] -> [T.Text] -> [T.Text] linesSetOperation ot = go-   where +   where       go :: [T.Text] -> [T.Text] -> [T.Text]       go [] [] = []       go xs [] = if otKeepRemainderLeft ot then xs else []       go [] xs = if otKeepRemainderRight ot then xs else []-      go left@(l:ls) right@(r:rs) = -         if (otCompare ot) l r +      go left@(l:ls) right@(r:rs) =+         if (otCompare ot) l r             then chosen : go (dropWhileChosen left) (dropWhileChosen right)             else case compare l r of                LT -> go ls   right@@ -101,18 +100,18 @@          where             chosen = (otChoose ot) l r             dropWhileChosen = dropWhile (== chosen)-      + data (Eq a, Ord a) => OperatorTools a = OT-   { otCompare :: a -> a -> Bool-   , otChoose  :: a -> a -> a-   , otKeepRemainderLeft :: Bool+   { otCompare            :: a -> a -> Bool+   , otChoose             :: a -> a -> a+   , otKeepRemainderLeft  :: Bool    , otKeepRemainderRight :: Bool-   } +   }  operatorTools :: Ord a => Operator -> OperatorTools a operatorTools And          = OT (==)            const False False -- fst or snd, it does not matter they are equal-operatorTools Or           = OT (const2 True)   min True True-operatorTools Difference   = OT (<)             const True False +operatorTools Or           = OT (const2 True)   min   True  True+operatorTools Difference   = OT (<)             const True  False  const2 :: a -> b -> c -> a const2 = const . const
README.markdown view
@@ -12,16 +12,6 @@  This works because [setdown is on hackage][7]! -### With nix for local development--If you want to install setdown locally using nix for local development then do the following:--    $ nix-shell-    $ cabal sandbox init-    $ cabal install--That should install setdown in development mode locally.  - ## What is setdown and how does it work?  Setdown is a command line tool for line based set operations. To use setdown you write a "setdown@@ -149,6 +139,16 @@     cabal run mydefinitions.setdown  That is all that there is to it!++### With nix for local development++If you want to install setdown locally using nix for local development then do the following:++    $ nix-shell+    $ cabal sandbox init+    $ cabal install++That should install setdown in development mode locally.    ## Contributing to the setdown project 
setdown.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.3+version:             0.1.0.4  -- A short (one-line) description of the package. synopsis:            Treating files as sets to perform rapid set manipulation.@@ -90,7 +90,7 @@                        -- Module Dependencies                        , filepath      >= 1.2 && < 3                        , directory     >= 1.1 && < 3-                       , containers    == 0.5.*+                       , containers    == 0.6.*                        , uuid          == 1.3.*                        , split         == 0.2.*                        , mtl           == 2.2.*