playing with >=>
Apparently in haskell if you teach a man to fish, he'll write more pointfree code.
This commit is contained in:
parent
3d2a9f8405
commit
c643136e32
4 changed files with 7 additions and 6 deletions
|
@ -83,7 +83,7 @@ keyValue size file = do
|
||||||
|
|
||||||
{- Extension preserving keys. -}
|
{- Extension preserving keys. -}
|
||||||
keyValueE :: SHASize -> FilePath -> Annex (Maybe Key)
|
keyValueE :: SHASize -> FilePath -> Annex (Maybe Key)
|
||||||
keyValueE size file = keyValue size file >>= maybe (return Nothing) addE
|
keyValueE size file = keyValue >>= maybe (return Nothing) addE
|
||||||
where
|
where
|
||||||
addE k = return $ Just $ k
|
addE k = return $ Just $ k
|
||||||
{ keyName = keyName k ++ extension
|
{ keyName = keyName k ++ extension
|
||||||
|
|
|
@ -69,7 +69,7 @@ performBare key backend = check
|
||||||
]
|
]
|
||||||
|
|
||||||
check :: [Annex Bool] -> CommandPerform
|
check :: [Annex Bool] -> CommandPerform
|
||||||
check s = sequence s >>= dispatch
|
check = sequence >=> dispatch
|
||||||
where
|
where
|
||||||
dispatch vs
|
dispatch vs
|
||||||
| all (== True) vs = next $ return True
|
| all (== True) vs = next $ return True
|
||||||
|
|
4
Limit.hs
4
Limit.hs
|
@ -67,7 +67,7 @@ addExclude glob = addLimit $ return . notExcluded
|
||||||
addIn :: String -> Annex ()
|
addIn :: String -> Annex ()
|
||||||
addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
|
addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
|
||||||
where
|
where
|
||||||
check a f = Backend.lookupFile f >>= handle a
|
check a = Backend.lookupFile >=> handle a
|
||||||
handle _ Nothing = return False
|
handle _ Nothing = return False
|
||||||
handle a (Just (key, _)) = a key
|
handle a (Just (key, _)) = a key
|
||||||
inremote key = do
|
inremote key = do
|
||||||
|
@ -83,7 +83,7 @@ addCopies num =
|
||||||
Nothing -> error "bad number for --copies"
|
Nothing -> error "bad number for --copies"
|
||||||
Just n -> addLimit $ check n
|
Just n -> addLimit $ check n
|
||||||
where
|
where
|
||||||
check n f = Backend.lookupFile f >>= handle n
|
check n = Backend.lookupFile >=> handle n
|
||||||
handle _ Nothing = return False
|
handle _ Nothing = return False
|
||||||
handle n (Just (key, _)) = do
|
handle n (Just (key, _)) = do
|
||||||
us <- keyLocations key
|
us <- keyLocations key
|
||||||
|
|
|
@ -8,15 +8,16 @@
|
||||||
module Utility.Misc where
|
module Utility.Misc where
|
||||||
|
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
{- A version of hgetContents that is not lazy. Ensures file is
|
{- A version of hgetContents that is not lazy. Ensures file is
|
||||||
- all read before it gets closed. -}
|
- all read before it gets closed. -}
|
||||||
hGetContentsStrict :: Handle -> IO String
|
hGetContentsStrict :: Handle -> IO String
|
||||||
hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
|
hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s
|
||||||
|
|
||||||
{- A version of readFile that is not lazy. -}
|
{- A version of readFile that is not lazy. -}
|
||||||
readFileStrict :: FilePath -> IO String
|
readFileStrict :: FilePath -> IO String
|
||||||
readFileStrict f = readFile f >>= \s -> length s `seq` return s
|
readFileStrict = readFile >=> \s -> length s `seq` return s
|
||||||
|
|
||||||
{- Attempts to read a value from a String. -}
|
{- Attempts to read a value from a String. -}
|
||||||
readMaybe :: (Read a) => String -> Maybe a
|
readMaybe :: (Read a) => String -> Maybe a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue