Question: I am new to Scala, I want the fastest way to get a map of count of occurrences for each character in a text file, how can I do that?(I used groupBy but I believe it is too slow)

Answer: 
I think that `groupBy()` is probably pretty efficient, but it simply collects the elements, which means that counting them requires a 2nd traversal.

To count all `Char`s in a single traversal you'd probably need something like this.

```
val tally = Array.ofDim[Long](127)
io.Source.fromFile("someFile.txt").foreach(tally(_) += 1)

```

`Array` was used for its fast indexing. The index is the character that was counted.

```
tally('e')  //res0: Long = 74
tally('x')  //res1: Long = 1

```
You can do the following:

Read the file first:

```
val lines = Source.fromFile("/Users/Al/.bash_profile").getLines.toSeq

```

You can then write a method that takes the List of lines read and counts the occurence for a given character:

```
  def getCharCount(c: Char, lines: Seq[String]) = {
    lines.foldLeft(0){(acc, elem) =>
      elem.toSeq.count(_ == c) + acc
    }
  }

```