Skip to content

Commit 0acf9bf

Browse files
committed
added more examples
1 parent 1ecbdee commit 0acf9bf

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/test/kotlin/kscript/examples/AwkComparison.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,21 @@ object AwkExample : OneLinerContext(args) {
1616

1717
lines.split().filter { it[3].matches("UA".toRegex()) }.print()
1818

19+
(1..3).asSequence().toList().toTypedArray()
1920
// remove header
21+
22+
val foo = arrayOf(*arrayOf(1..3).toList().toTypedArray())
23+
24+
25+
2026
lines.drop(1).split().filter { it[3].matches("UA".toRegex()) }.print()
2127

2228

29+
// positive selection
30+
lines.split().select(with(1..3).and(3)).print()
31+
// negative selection
32+
lines.split().select(without(7).and(3..4)).print()
33+
2334
lines.awk { it[1] + it[2] }
2435

2536
lines.awk { it[1] + it[2] }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package kscript.test
2+
3+
import kscript.text.*
4+
5+
/**
6+
* @author Holger Brandl
7+
*/
8+
9+
fun flightsHead() = resolveArgFile(arrayOf("flights_head.txt"))
10+
11+
fun flightsZipped() = resolveArgFile(arrayOf("flights.tsv.gz"))
12+
fun flights() = resolveArgFile(arrayOf("flights.txt"))
13+
14+
// just used for testing and development
15+
fun linesFrom(vararg lines: String) = lines.asSequence()
16+
17+
18+
fun main(args: Array<String>) {
19+
// remove header
20+
flightsHead().drop(1).take(5)
21+
22+
23+
// positive selection
24+
System.out.println("positive selection")
25+
// flightsHead().split().select(with(1..3).and(3)).print()
26+
flightsHead().split().select(1, 10, 12).print()
27+
flightsHead().split().select(10, 1, 12).print()
28+
29+
//create column
30+
//create column
31+
flightsHead().split().map { listOf(it[1], it[2], "F11-" + it[7]) }.print()
32+
33+
// negative selection
34+
System.out.println("negative selection")
35+
flightsHead().split().select(without(7).and(3..4)).print()
36+
}

0 commit comments

Comments
 (0)