Skip to content

Commit ba60a49

Browse files
committed
Обновлены примеры
1 parent c382c4e commit ba60a49

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def f() = def() = def() = def() = "Function call chaining: f()()()()"
2+
3+
println f()()()()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def calc() = {
2+
"add": ::add,
3+
"sub": ::minus
4+
}
5+
def add(x, y) = x + y
6+
def minus(x, y) = x - y
7+
8+
println calc().add(77, 42)
9+
println calc().sub(77, 42)

examples/functions/stream.own

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use "std"
2+
use "functional"
3+
4+
println "x, square(x), cube(x) for even numbers"
5+
data = [1,2,3,4,5,6,7,8,9]
6+
stream(data)
7+
.filter(def(x) = x % 2 == 0)
8+
.map(def(x) = [x, x * x, x * x * x])
9+
.sortBy(def(x) = -x[2])
10+
.forEach(::echo)
11+
12+
13+
println "\nReverse custom operator"
14+
data = [2, 4, 6, 5, 12, 34, 0, 18]
15+
rev = stream(data).custom(::reverse).toArray()
16+
println data
17+
println rev
18+
19+
def reverse(container) {
20+
size = length(container)
21+
result = newarray(size)
22+
for i : range(size) {
23+
result[size - i - 1] = container[i]
24+
}
25+
return result
26+
}

examples/java/system_info.own

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use "java"
2+
System = newClass("java.lang.System")
3+
println "OS name: " + System.getProperty("os.name")
4+
println "OS version: " + System.getProperty("os.version")
5+
println "User home: " + System.getProperty("user.home")

0 commit comments

Comments
 (0)