/**
 * Illustrates flatMap + countByValue for wordcount.
 */
package com.oreilly.learningsparkexamples.scala

import org.apache.spark._
import org.apache.spark.SparkContext._

object WordCount {
    def main(args: Array[String]) {
      val master = args.length match {
        case x: Int if x > 0 => args(0)
        case _ => "local"
      }
      val sc = new SparkContext(master, "WordCount", System.getenv("SPARK_HOME"))
      val input = args.length match {
        case x: Int if x > 1 => sc.textFile(args(1))
        case _ => sc.parallelize(List("pandas", "i like pandas"))
      }
      val counts = input.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _)
      args.length match {
        case x: Int if x > 2 => counts.saveAsTextFile(args(2))
        case _ => println(counts.collect().mkString(","))
      }
    }
}

/**
 * Illustrates flatMap + countByValue for wordcount.
 */
package com.oreilly.learningsparkexamples.scala

import org.apache.spark._
import org.apache.spark.SparkContext._

object WordCount {
    def main(args: Array[String]) {
      val master = args.length match {
        case x: Int if x > 0 => args(0)
        case _ => "local"
      }
      val sc = new SparkContext(master, "WordCount", System.getenv("SPARK_HOME"))
      val input = args.length match {
        case x: Int if x > 1 => sc.textFile(args(1))
        case _ => sc.parallelize(List("pandas", "i like pandas"))
      }
      val words = input.flatMap(_.split(" "))
      args.length match {
        case x: Int if x > 2 => {
          val counts = words.map((_, 1)).reduceByKey(_ + _)
          counts.saveAsTextFile(args(2))
        }
        case _ => {
          val wc = words.countByValue()
          println(wc.mkString(","))
        }
      }
    }
}

Make the wordcount example match its description (we didn't use countbyvalue before)
Make the wordcount example match its description (we didn't use countbyvalue before)
