Permalink
Browse files

Added point-free "optionalArgs" implementation.

  • Loading branch information...
1 parent 06f7f0b commit ed344bad69294bb989f375011fd6031050b93301 @lukehoersten committed Dec 22, 2012
Showing with 8 additions and 9 deletions.
  1. +8 −9 src/Web/Stripe/Utils.hs
View
@@ -15,17 +15,18 @@ module Web.Stripe.Utils
, showByteString
) where
-import Data.Time.Clock (UTCTime (..))
-import Data.Time.Clock.POSIX (posixSecondsToUTCTime,
- utcTimeToPOSIXSeconds)
-import Data.Time.Format ()
-
import qualified Codec.Binary.UTF8.String as CodecUtf8
+import Control.Monad (liftM)
import Data.Aeson (Value (..), decode)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.HashMap.Lazy as HML
+import Data.Maybe (mapMaybe)
import qualified Data.Text as T
+import Data.Time.Clock (UTCTime (..))
+import Data.Time.Clock.POSIX (posixSecondsToUTCTime,
+ utcTimeToPOSIXSeconds)
+import Data.Time.Format ()
showByteString :: Show a => a -> B.ByteString
showByteString = stringToByteString . show
@@ -83,7 +84,5 @@ toSeconds = round . utcTimeToPOSIXSeconds
--
-- >>> optionalArgs [("k1", Just "supplied"), ("k2", Nothing)]
-- [("k1","supplied")]
-optionalArgs :: [(a, Maybe a)] -> [(a, a)]
-optionalArgs [] = []
-optionalArgs ((_, Nothing):xs) = optionalArgs xs
-optionalArgs ((a, Just b):xs) = (a, b):optionalArgs xs
+optionalArgs :: [(a, Maybe b)] -> [(a, b)]
+optionalArgs = mapMaybe . uncurry $ liftM . (,)

2 comments on commit ed344ba

point{ free | less } programming FTW!

to be honest, I'm always conflicted about these kind of changes. they're slicker but do make the code a bit harder to read. anyway, I'm mostly indifferent and fine with it.

Owner

lukehoersten replied Dec 31, 2012

Agreed. I figured in this case the function is simple enough that it's worth it and the signature is clear enough.

Please sign in to comment.