alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TestFlatMap.scala)

This example Scala source code file (TestFlatMap.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, array, compositethrowable, int, int, m, n, pmhashset, pmhashset, range, range, test

The Scala TestFlatMap.scala source code

import scala.collection.parallel.{ ParMap => PMap }
import scala.collection.parallel.mutable.{ ParHashSet => PMHashSet, ParHashMap => PMHashMap, ParArray }
import scala.util.Random
import scala.collection.parallel.CompositeThrowable

object Test {
  
  def main(args: Array[String]) {
    val N = 1500
    val M = 1500
    var unmatchedLeft = new PMHashSet[Int]
    var unmatchedRight = new PMHashSet[Int]
    Range(0, N).foreach{ x => unmatchedLeft += x}
    Range(0, M).foreach{ x => unmatchedRight += x}
    
    try {
      val matches = unmatchedLeft.flatMap{ lind: Int =>
        val dists = unmatchedRight.seq.map{ rind: Int =>
          val dist = Random.nextInt
          (rind, dist)
        }
        dists
      }
    } catch {
      case c: CompositeThrowable => for (t <- c.throwables) println("\n%s\n%s".format(t, t.getStackTrace.mkString("\n")))
    }
  }
  
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala TestFlatMap.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.