Обновлены примеры

This commit is contained in:
Victor 2016-09-13 14:29:00 +03:00
parent c382c4eab6
commit ba60a498d7
4 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,3 @@
def f() = def() = def() = def() = "Function call chaining: f()()()()"
println f()()()()

View File

@ -0,0 +1,9 @@
def calc() = {
"add": ::add,
"sub": ::minus
}
def add(x, y) = x + y
def minus(x, y) = x - y
println calc().add(77, 42)
println calc().sub(77, 42)

View File

@ -0,0 +1,26 @@
use "std"
use "functional"
println "x, square(x), cube(x) for even numbers"
data = [1,2,3,4,5,6,7,8,9]
stream(data)
.filter(def(x) = x % 2 == 0)
.map(def(x) = [x, x * x, x * x * x])
.sortBy(def(x) = -x[2])
.forEach(::echo)
println "\nReverse custom operator"
data = [2, 4, 6, 5, 12, 34, 0, 18]
rev = stream(data).custom(::reverse).toArray()
println data
println rev
def reverse(container) {
size = length(container)
result = newarray(size)
for i : range(size) {
result[size - i - 1] = container[i]
}
return result
}

View File

@ -0,0 +1,5 @@
use "java"
System = newClass("java.lang.System")
println "OS name: " + System.getProperty("os.name")
println "OS version: " + System.getProperty("os.version")
println "User home: " + System.getProperty("user.home")