Mon Nov 12 01:02:30 MST 2007  Kevin Quick <[EMAIL PROTECTED]>
  * Added maybeGetEnv and firstJustIO for get_easy_author operation reduction 
(and simplification).
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


New patches:

[Added maybeGetEnv and firstJustIO for get_easy_author operation reduction (and simplification).
Kevin Quick <[EMAIL PROTECTED]>**20071112080230] {
hunk ./src/Darcs/Arguments.lhs 77
- -import System ( ExitCode(ExitFailure, ExitSuccess), exitWith, getEnv )
+import System ( ExitCode(ExitFailure, ExitSuccess), exitWith )
hunk ./src/Darcs/Arguments.lhs 79
- -import Control.Monad ( liftM, mplus, when, unless )
+import Control.Monad ( liftM, when, unless )
hunk ./src/Darcs/Arguments.lhs 85
- -import Darcs.Utils ( askUser, catchall )
+import Darcs.Utils ( askUser, maybeGetEnv, firstNotBlank, firstJustIO )
hunk ./src/Darcs/Arguments.lhs 562
- -get_easy_author = do
- -  pref_author <- author_pref
- -  easy_author <- try_author [getEnv "DARCS_EMAIL",
- -                             getEnv "EMAIL"]
- -  return $ pref_author `mplus` easy_author
- -    where try_author (g:gs) = (liftM Just g) `catchall` try_author gs
- -          try_author [] = return Nothing
- -          author_pref = do au <- get_preflist "author"
- -                           augl <- get_global "author"
- -                           case au++augl of [] -> return Nothing
- -                                            (a:_) -> return $ Just a
+get_easy_author = firstJustIO [ get_preflist "author" >>= return . firstNotBlank,
+                                get_global "author" >>= return .firstNotBlank,
+                                maybeGetEnv "DARCS_EMAIL",
+                                maybeGetEnv "EMAIL" ]
hunk ./src/Darcs/Utils.lhs 12
+                    maybeGetEnv, firstNotBlank, firstJustM, firstJustIO,
hunk ./src/Darcs/Utils.lhs 32
+import Data.Maybe ( listToMaybe, isJust )
hunk ./src/Darcs/Utils.lhs 73
+maybeGetEnv :: String -> IO (Maybe String)
+maybeGetEnv s = (getEnv s >>= return.Just) `catchall` return Nothing -- err can only be isDoesNotExist
+
+
+-- |The firstJustM returns the first Just entry in a list of monadic operations.  This is close to
+--  `listToMaybe `fmap` sequence`, but the sequence operator evaluates all monadic members of the
+--  list before passing it along (i.e. sequence is strict).  The firstJustM is lazy in that list
+--  member monads are only evaluated up to the point where the first Just entry is obtained.
+firstJustM :: Monad m => [m (Maybe a)] -> m (Maybe a)
+firstJustM [] = return Nothing
+firstJustM (e:es) = e >>= (\v -> if isJust v then return v else firstJustM es)
+
+-- |The firstJustIO is a slight modification to firstJustM: the
+--  entries in the list must be IO monad operations and the
+--  firstJustIO will silently turn any monad call that throws an
+--  exception into Nothing, basically causing it to be ignored.
+firstJustIO :: [IO (Maybe a)] -> IO (Maybe a)
+firstJustIO = firstJustM . map (\o -> o `catchall` return Nothing)
+
+
hunk ./src/Darcs/Utils.lhs 149
+-- |Returns Just l where l is first non-blank string in input array; Nothing if no non-blank entries
+firstNotBlank :: [String] -> Maybe String
+firstNotBlank = listToMaybe . filter ((/=) "")
+
+
}

Context:

[TAG darcs unstable 2007-11-04
Eric Kow <[EMAIL PROTECTED]>**20071104235616] 
Patch bundle hash:
9a070306a96c44a186736e8668cd905964054149
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.6 (GNU/Linux)

iD8DBQFHOOimt76lKrRL0ewRAo0QAJ9Qieq3pfjL17Gs6lAEjrBte2laLQCdEJLi
lW4FvhDCKVrGLtlCeKj/hRY=
=Yi6L
-----END PGP SIGNATURE-----
_______________________________________________
darcs-devel mailing list
[email protected]
http://lists.osuosl.org/mailman/listinfo/darcs-devel

Reply via email to