Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using map with two lists rather than one. Can you nest?
- runParseTest :: String -> String -> IO()
- -- Get list of files in libraries directory
- files <- getDirectoryContents "tests/libraries"
- -- Filter out ".." and "." and add path
- let names = filter (x -> head x /= '.') files
- let libs = ["tests/libraries/" ++ f | f <- names]
- runParseTest "test1.js" "tests/libraries/test1.js"
- runParseTest "test2.js" "tests/libraries/test2.js"
- runParseTest "test3.js" "tests/libraries/test3.js"
- mapM_ (runParseTest "test") libs
- map ((a,b) -> runParseTest a b) $ zip names libs
- map (uncurry runParseTest) $ zip names libs
- zipWith runParseTest names libs
- > :t zipWithM
- zipWithM :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- > :t zipWithM_
- zipWithM_ :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m ()
- import Data.List (isPrefixOf)
- ...
- -- I got rid of `head` because it's a partial function, and I prefer `map` to
- -- list comprehensions for simple things
- do files <- getDirectoryContents "tests/libraries"
- let names = filter (not . ("." `isPrefixOf`)) files
- libs = map ("tests/libraries/" ++) names
- zipWithM_ runParseTest names libs
- map2 :: (a -> b -> c) -> [a] -> [b] -> [c]
- map2 _ [] _ = []
- map2 _ _ [] = []
- map2 f (a:as) (b:bs) = f a b : map2 f as bs
- map2M_ :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m ()
- map2M_ f as bs = sequence_ (map2 f as bs)
Advertisement
Add Comment
Please, Sign In to add comment