Skip to content

Commit 80b7554

Browse files
committed
refined filter and map utils
1 parent cb1f81b commit 80b7554

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/kotlin/kscript/StreamUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ fun argLines(arg: String, stdinNames: List<String> = listOf("-", "stdin")): Sequ
2424
return BufferedReader(FileReader(inputFile)).lineSequence()
2525
}
2626

27-
fun mapLines(arg: String, stdinNames: List<String> = listOf("-", "stdin"), trafo: (String) -> String) =
27+
fun argMap(arg: String, stdinNames: List<String> = listOf("-", "stdin"), trafo: (String) -> String) =
2828
argLines(arg, stdinNames).map { trafo(it) }.print()
2929

30-
fun filterLines(arg: String, stdinNames: List<String> = listOf("-", "stdin"), trafo: (String) -> Boolean) =
30+
fun argFilter(arg: String, stdinNames: List<String> = listOf("-", "stdin"), trafo: (String) -> Boolean) =
3131
argLines(arg, stdinNames).filter { trafo(it) }.print()
3232

3333

src/test/kotlin/kscript/test/SupportApiTest.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ package kscript.test
33
import io.kotlintest.matchers.shouldBe
44
import io.kotlintest.specs.StringSpec
55
import kscript.*
6+
import java.io.File
67

78
/**
89
* @author Holger Brandl
910
*/
1011
class SupportApiTest : StringSpec() { init {
1112

12-
"length should return size of string" {
13-
"hello".length shouldBe 5
14-
}
15-
1613
"allow to use stdin for filtering and mapping" {
1714
stdin.filter { "^de0[-0]*".toRegex().matches(it) }.map { it + "foo:" }.print()
1815
}
16+
17+
"length should return size of string" {
18+
// "hello".length shouldBe 5
19+
// stopIfNot("FOO"=="BAR"){"condition not met"}
20+
println("current dir is " + File(".").absolutePath)
21+
argMap("src/test/resources/flights_head.txt") { it.split("\t")[7] }
22+
argFilter("src/test/resources/flights_head.txt") { it.split("\t")[7] == "UA" }
23+
}
1924
}
2025
}

0 commit comments

Comments
 (0)