Update examples

This commit is contained in:
aNNiMON 2024-04-28 22:39:30 +03:00
parent ae42c0952a
commit 165b930342
4 changed files with 67 additions and 2 deletions

View File

@ -105,11 +105,10 @@ for y : 1 .. 10 {
Easy async HTTP requests with `http` module. Easy async HTTP requests with `http` module.
```scala ```scala
use std, http, functional use std, http, functional, json
// GET request // GET request
http("https://api.github.com/events", def(r) { http("https://api.github.com/events", def(r) {
use json
events = jsondecode(r) events = jsondecode(r)
println events[0] println events[0]
}) })

View File

@ -0,0 +1,12 @@
use std, functional
data = ["apple", "banana", "cherry", "apricot", "coconut"]
println groupby(data, def(str) = str.substring(0, 1))
map = {"abc": 123, "test1": 234, "test2": 345, "test3": 456, "def": 567}
println groupby(map, def(k, v) = k.startsWith("test"))
arr = [1, 2, 3, 4, 1, 2, 3, 1, 2, 3]
result = groupby(arr, def(v) = v % 2 == 0)
println "even: " + result[true]
println "odd: " + result[false]

View File

@ -0,0 +1,8 @@
use std, functional
data = ["apple", "banana", "cherry", "apricot", "coconut"]
println tomap(data, def(str) = str.substring(0, 1))
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase)
println tomap(data, def(str) = str.substring(0, 1), ::toUpperCase, ::joinValues)
def joinValues(oldValue, newValue) = oldValue + ", " + newValue

View File

@ -0,0 +1,46 @@
use std
title("Breaking changes")
println "Minimal Java version is 17"
println "Simplified use statement: use std, math"
println "More strict lexer"
title("Changes")
println "Support for long number declaration:"
println " Int overflow: " + (1000000*7000)
println " Long " + (1000000*7000L)
println "Better error visualizing"
println "Semantic linter as a required stage"
println "Preserve the order of Map elements by default:"
map = {"first": 1, "second": 2, "third": 3}
println " " + map
println "Ability to run programs from resources by adding \"resource:\" prefix to path"
println "Added internal scripts and command `ownlang run` to run them"
include "resource:/scripts/listscripts.own"
title("Modules")
println "std::parseDouble:"
println " -.2e5: " + parseDouble("-.2e5")
println "std::nanotime:"
println " " + nanotime()
println "std::getenv"
println " Env.variable JAVA_HOME: " + getenv("JAVA_HOME", "N/A")
println "std::getprop"
println " Property ownlangScript: " + getenv("ownlangScript", "N/A")
println "http::httpSync"
println "functional"
println " groupby, tomap"
println "functional Stream"
println " groupBy, filterNot, forEachIndexed, toMap, anyMatch, allMatch, noneMatch"
println "canvasfx works for Java 17+ (Windows only)"
println "new server module"
// helpers
def title(s) {
println "\n"
println "=" * s.length
println s
println "=" * s.length
}