smap 0.2.0 → 0.2.1
raw patch · 2 files changed
+10/−14 lines, 2 files
Files
- smap.cabal +3/−3
- src/Smap/Commands.hs +7/−11
smap.cabal view
@@ -4,12 +4,12 @@ -- -- see: https://github.com/sol/hpack ----- hash: db4e5b07ac8350e9046998e591625af97e33131e0c2b52007a60ad66cb2f65a6+-- hash: f341330ce026ba29d5e5b23a17af3e56e1a415c1dc7d595c07a06ffe622d12ce name: smap-version: 0.2.0+version: 0.2.1 synopsis: A command line tool for working with sets and maps-description: Please see the README on GitHub below or at <https://github.com/wyager/smap>+description: Please see the README below or on GitHub at <https://github.com/wyager/smap> category: Text homepage: https://github.com/wyager/smap#readme bug-reports: https://github.com/wyager/smap/issues
src/Smap/Commands.hs view
@@ -13,7 +13,6 @@ import Data.Strict.Tuple (Pair((:!:))) import Data.List.NonEmpty (NonEmpty((:|))) import qualified Control.Monad.Trans.Resource as Resource-import Control.Monad.IO.Class (MonadIO) import Crypto.MAC.SipHash (SipHash(..), hash) import Smap.Flags ( Hdl(Std, File)@@ -24,11 +23,13 @@ type Stream m k v = S.Stream (S.Of (Pair k v)) m () +type RIO = Resource.ResourceT IO+ type SetOperation = forall key . (Hashable key, Eq key)- => NonEmpty (Stream (Resource.ResourceT IO) key ByteString) -- Input maps- -> Stream (Resource.ResourceT IO) key ByteString -- Output map+ => NonEmpty (Stream RIO key ByteString) -- Input maps+ -> Stream RIO key ByteString -- Output map cat :: SetOperation cat streams = foldM filter Map.empty streams *> return ()@@ -53,7 +54,7 @@ int :: SetOperation int = filterStreamWith id -load :: (MonadIO m, Resource.MonadResource m) => Descriptor ty -> Stream m ByteString ByteString+load :: Descriptor ty -> Stream RIO ByteString ByteString load descriptor = case descriptor of UnKeyed hdl -> P.map (\x -> x :!: x) (linesOf hdl) Keyed keys values -> S.zipsWith'@@ -66,19 +67,14 @@ hin (File path) = BS8.readFile path withAccuracy- :: Accuracy- -> SetOperation- -> NonEmpty (Stream (Resource.ResourceT IO) ByteString ByteString)- -> Hdl- -> IO ()+ :: Accuracy -> SetOperation -> NonEmpty (Stream RIO ByteString ByteString) -> Hdl -> IO () withAccuracy accuracy op inputs output = case accuracy of Exact -> approximateWith id- Approximate key -> approximateWith (sip key)+ Approximate key -> approximateWith (\bs -> let SipHash h = hash key bs in h) where format = BS8.unlines . S.maps (\((_k :!: v) P.:> r) -> BS8.fromStrict v >> return r) hout Std = BS8.stdout hout (File path) = BS8.writeFile path- sip key bs = let SipHash h = hash key bs in h keyMap f = P.map (\(k :!: v) -> (f k :!: v)) approximateWith approximator = Resource.runResourceT $ hout output $ format $ op $ fmap (keyMap approximator) inputs