Skip to content

Commit 165b930

Browse files
committed
Update examples
1 parent ae42c09 commit 165b930

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ for y : 1 .. 10 {
105105
Easy async HTTP requests with `http` module.
106106

107107
```scala
108-
use std, http, functional
108+
use std, http, functional, json
109109

110110
// GET request
111111
http("https://api.github.com/events", def(r) {
112-
use json
113112
events = jsondecode(r)
114113
println events[0]
115114
})

examples/functions/groupby.own

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std, functional
2+
3+
data = ["apple", "banana", "cherry", "apricot", "coconut"]
4+
println groupby(data, def(str) = str.substring(0, 1))
5+
6+
map = {"abc": 123, "test1": 234, "test2": 345, "test3": 456, "def": 567}
7+
println groupby(map, def(k, v) = k.startsWith("test"))
8+
9+
arr = [1, 2, 3, 4, 1, 2, 3, 1, 2, 3]
10+
result = groupby(arr, def(v) = v % 2 == 0)
11+
println "even: " + result[true]
12+
println "odd: " + result[false]

examples/functions/tomap.own

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std, functional
2+
3+
data = ["apple", "banana", "cherry", "apricot", "coconut"]
4+
println tomap(data, def(str) = str.substring(0, 1))
5+
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase)
6+
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase, ::joinValues)
7+
8+
def joinValues(oldValue, newValue) = oldValue + ", " + newValue

examples/versions/whatsnew_2.0.0.own

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std
2+
3+
title("Breaking changes")
4+
println "Minimal Java version is 17"
5+
println "Simplified use statement: use std, math"
6+
println "More strict lexer"
7+
8+
title("Changes")
9+
println "Support for long number declaration:"
10+
println " Int overflow: " + (1000000*7000)
11+
println " Long " + (1000000*7000L)
12+
println "Better error visualizing"
13+
println "Semantic linter as a required stage"
14+
println "Preserve the order of Map elements by default:"
15+
map = {"first": 1, "second": 2, "third": 3}
16+
println " " + map
17+
println "Ability to run programs from resources by adding \"resource:\" prefix to path"
18+
println "Added internal scripts and command `ownlang run` to run them"
19+
include "resource:/scripts/listscripts.own"
20+
21+
title("Modules")
22+
println "std::parseDouble:"
23+
println " -.2e5: " + parseDouble("-.2e5")
24+
println "std::nanotime:"
25+
println " " + nanotime()
26+
println "std::getenv"
27+
println " Env.variable JAVA_HOME: " + getenv("JAVA_HOME", "N/A")
28+
println "std::getprop"
29+
println " Property ownlangScript: " + getenv("ownlangScript", "N/A")
30+
println "http::httpSync"
31+
32+
println "functional"
33+
println " groupby, tomap"
34+
println "functional Stream"
35+
println " groupBy, filterNot, forEachIndexed, toMap, anyMatch, allMatch, noneMatch"
36+
37+
println "canvasfx works for Java 17+ (Windows only)"
38+
println "new server module"
39+
40+
// helpers
41+
def title(s) {
42+
println "\n"
43+
println "=" * s.length
44+
println s
45+
println "=" * s.length
46+
}

0 commit comments

Comments
 (0)