Browse files

polish java end of history sample

  • Loading branch information...
1 parent c4b95f4 commit f72999093a0ee52e4b9134b41d55276338cb533b @geraldb geraldb committed Jul 5, 2012
Showing with 10 additions and 10 deletions.
  1. +10 −10 samples/java_end_of_history.text
View
20 samples/java_end_of_history.text
@@ -161,19 +161,19 @@ Anyone?
%%% todo: escape numbered list in markdown how?
-(1.) Multiple Each Item in a List by 2
+1) Multiple Each Item in a List by 2
```
(1 to 10) map { _ * 2 }
```
-(2.) Sum a List of Numbers
+2) Sum a List of Numbers
```
(1 to 1000).sum
```
-(3.) Verify if Exists in a String
+3) Verify if Exists in a String
```
val wordList = List("scala", "akka", "play framework", "sbt", "typesafe")
@@ -182,14 +182,14 @@ val tweet = "This is an example tweet talking about scala and sbt."
wordList.exists(tweet.contains)
```
-(4.) Read in a File
+4) Read in a File
```
val fileText = io.Source.fromFile("data.txt").mkString
val fileLines = io.Source.fromFile("data.txt").getLines.toList
```
-(5.) Happy Birthday to You!
+5) Happy Birthday to You!
```
(1 to 4).map { i => "Happy Birthday " + (if (i == 3) "dear NAME" else "to You") }.foreach { println }
@@ -198,34 +198,34 @@ val fileLines = io.Source.fromFile("data.txt").getLines.toList
# 10 Scala One Liners Continued
-(6.) Filter list of numbers
+6) Filter list of numbers
```
val (passed, failed) = List(49, 58, 76, 82, 88, 90) partition ( _ > 60 )
```
-(7.) Fetch and Parse an XML web service
+7) Fetch and Parse an XML web service
```
val results = XML.load("http://search.twitter.com/search.atom?&q=scala")
```
-(8.) Find minimum (or maximum) in a List
+8) Find minimum (or maximum) in a List
```
List(14, 35, -7, 46, 98).min
List(14, 35, -7, 46, 98).max
```
-(9.) Parallel Processing
+9) Parallel Processing
```
val result = dataList.par.map(line => processItem(line))
```
-(10.) Sieve of Eratosthenes
+10) Sieve of Eratosthenes
```
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))

0 comments on commit f729990

Please sign in to comment.