Skip to content

Instantly share code, notes, and snippets.

@j1r1k
Created May 28, 2016 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1r1k/f5c8d8fdc211f60e28544f152bf036b2 to your computer and use it in GitHub Desktop.
Save j1r1k/f5c8d8fdc211f60e28544f152bf036b2 to your computer and use it in GitHub Desktop.
PureScript by Example: Chapter 12 (Callback Hell) exercise 12.8.1
module ParallelConcat where
import Prelude (Unit, (<<<), ($), bind)
import Types (Async)
import Control.Monad.Except.Trans (ExceptT, mapExceptT)
import Control.Parallel (inParallel, runParallel)
import Data.Foldable (fold)
import Data.Traversable (class Traversable, traverse)
import Files (ErrorCode, FilePath, FS, readFileContEx, writeFileContEx)
concatenateMany :: forall eff t. Traversable t => t FilePath -> FilePath -> ExceptT ErrorCode (Async (fs :: FS | eff)) Unit
concatenateMany srcs trg = do
c <- mapExceptT runParallel $ traverse (mapExceptT inParallel <<< readFileContEx) srcs
writeFileContEx trg (fold c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment