Skip to content

Instantly share code, notes, and snippets.

@bohde
Created February 15, 2015 03:47
Show Gist options
  • Save bohde/8cd9f933a33101c93b49 to your computer and use it in GitHub Desktop.
Save bohde/8cd9f933a33101c93b49 to your computer and use it in GitHub Desktop.
module Foo where
import Control.Applicative
import Data.Set (Set)
import Data.Map (Map)
import qualified Data.Map as M
import qualified Data.Set as S
get :: String -> IO (Maybe String)
get = undefined
multiGet :: Set String -> IO (Map String String)
multiGet = undefined
test :: IO (Maybe String, Maybe String, Maybe String)
test = (,,) <$> get "foo" <*> get "bar" <*> get "baz"
unbatch :: Map String a -> (Maybe a, Maybe a, Maybe a)
unbatch = (,,) <$> M.lookup "foo" <*> M.lookup "bar" <*> M.lookup "baz"
fetch :: IO (Map String String)
fetch = multiGet $ S.fromList ["foo", "bar", "baz"]
testBatch :: IO (Maybe String, Maybe String, Maybe String)
testBatch = unbatch <$> fetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment