Mercurial > hg > Members > nobuyasu > scala
comparison chapter7/someGenerator.scala @ 0:b316eec6fa7a draft default tip
add sample files
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jan 2013 16:41:46 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b316eec6fa7a |
---|---|
1 val filesHere = (new java.io.File(".")).listFiles | |
2 def fileLines(file: java.io.File) = | |
3 scala.io.Source.fromFile(file).getLines.toList | |
4 def grep(pattern: String) = | |
5 for ( | |
6 file <- filesHere | |
7 if file.getName.endsWith(".scala"); | |
8 line <- fileLines(file) | |
9 if line.trim.matches(pattern) | |
10 ) println(file +": "+ line.trim) | |
11 grep(".*gcd.*") | |
12 | |
13 def grep2(pattern: String) = | |
14 for { | |
15 file <- filesHere | |
16 if file.getName.endsWith(".scala") | |
17 line <- fileLines(file) | |
18 trimmed = line.trim | |
19 if trimmed.matches(pattern) | |
20 } println(file +": "+ trimmed) | |
21 grep2(".*gcd.*") | |
22 | |
23 | |
24 | |
25 | |
26 |