mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Update examples
This commit is contained in:
parent
ae42c0952a
commit
165b930342
@ -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]
|
||||||
})
|
})
|
||||||
|
12
examples/functions/groupby.own
Normal file
12
examples/functions/groupby.own
Normal 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]
|
8
examples/functions/tomap.own
Normal file
8
examples/functions/tomap.own
Normal 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
|
46
examples/versions/whatsnew_2.0.0.own
Normal file
46
examples/versions/whatsnew_2.0.0.own
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user