Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple disposers #278

Closed
pathikrit opened this issue Dec 5, 2018 · 0 comments
Closed

Add support for multiple disposers #278

pathikrit opened this issue Dec 5, 2018 · 0 comments
Labels

Comments

@pathikrit
Copy link
Owner

e.g.

def run(inputDir: File, outputDir: File, partitions: Int = 10) = {
    implicit def disposeMultiple[A](c: Disposable[A]): Disposable[IndexedSeq[A]] = Disposable(_.foreach(c.dispose))
    val lineCount = new AtomicInteger
    for {
      writers <- IndexedSeq.tabulate(partitions)(i => (outputDir / s"part-$i.csv.gz").newGzipOutputStream().printWriter()).autoDisposed
      file <- inputDir.list(filter = _.extension == Some(".csv")).toSeq.par
      line <- file.lineIterator.drop(1)
    } writers(lineCount.incrementAndGet() % partitions).println(line)
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant