Permalink
Browse files

add couple more combinators

  • Loading branch information...
1 parent effe236 commit 89b545d1227963bcd4b6926ee66b107b9b04859e @tonymorris committed Jan 18, 2012
Showing with 31 additions and 2 deletions.
  1. +6 −2 Command.cabal
  2. +25 −0 src/System/Command.hs
View
@@ -1,5 +1,5 @@
Name: Command
-Version: 0.0.3
+Version: 0.0.4
License: BSD3
License-File: LICENSE
Author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>
@@ -9,9 +9,13 @@ Category: System
Homepage: https://github.com/tonymorris/command
Description:
Specifically, this library replaces @System.Exit.ExitCode@ with an abstract data type.
-Cabal-Version: >= 1.2
+Cabal-Version: >= 1.6
Build-Type: Simple
+Source-Repository head
+ Type: git
+ Location: git@github.com:tonymorris/command.git
+
Flag small_base
Description: Choose the new, split-up base package.
View
@@ -32,8 +32,10 @@ module System.Command
, exitSuccess
, (->>)
, (->>>)
+, (->->)
, (<<-)
, (<<<-)
+, (<-<-)
, runExitCodes
-- * Process completion
, waitForProcess
@@ -177,6 +179,18 @@ a ->>> b =
do a' <- a
if isSuccess a' then b >> return () else return ()
+-- | Runs the first action.
+--
+-- Only if the result is successful, run the second action returning the first action's result.
+(->->) ::
+ Monad m =>
+ m ExitCode
+ -> m a
+ -> m ExitCode
+a ->-> b =
+ do a' <- a
+ if isSuccess a' then b >> return a' else return a'
+
-- | Runs the second action.
--
-- Only if the result is successful, run the first action returning its result.
@@ -199,6 +213,17 @@ a ->>> b =
(<<<-) =
flip (->>>)
+-- | Runs the second action.
+--
+-- Only if the result is successful, run the first action returning the second action's result.
+(<-<-) ::
+ Monad m =>
+ m a
+ -> m ExitCode
+ -> m ExitCode
+(<-<-) =
+ flip (->->)
+
-- | Run the structure of actions stopping at the first failure.
runExitCodes ::
(Monad m, Foldable f) =>

0 comments on commit 89b545d

Please sign in to comment.