Using the symbols >>= (bind) <$> (fmap) and <*> we can improve our Haskell programs. For example:

1
2
3
4
5
6
7
8
9
extractDomain :: Text -> Text
extractDomain url =
    case parseURI (unpack url) of
        Nothing -> ""
        Just uri ->
            case uriAuthority uri of
                Nothing -> ""
                Just auth -> pack $ uriRegName auth

1
2
3
4
5
extractDomainB :: Text -> Text
extractDomainB url = fromMaybe "" $ parseURI (unpack url)
                     >>= uriAuthority
                     >>= pure . pack . uriRegName

1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- | Retrieve the members of a set
sout :: Connection -> ByteString -> IO [ByteString] -- (Either Reply [ByteString])
sout conn k = do
  members <-
    liftIO $
    runRedis conn $ do
      res <- (smembers k)
      mem <-
        case res of
          Left _ -> return [] -- Hmm
          Right m -> return m
      return mem
  return members
1
2
3
4
-- | Retrieve the members of a set
sout :: Connection -> ByteString -> IO [ByteString]
sout conn k = 
    runRedis conn $ either (return []) id <$> smembers k