mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Add collections documentation
This commit is contained in:
parent
02fd959e58
commit
73662814ca
@ -7,6 +7,7 @@ OUTPUT_PATH_FMT = OUTPUT_DIR_FMT + "/%s.md"
|
||||
LANGS = ["en", "ru"]
|
||||
MODULES = [
|
||||
"std",
|
||||
"collections",
|
||||
"date",
|
||||
"downloader",
|
||||
"files",
|
||||
|
26
docs/src/modules/collections.yml
Normal file
26
docs/src/modules/collections.yml
Normal file
@ -0,0 +1,26 @@
|
||||
name: collections
|
||||
scope: both
|
||||
desc: Contains functions for working with collections
|
||||
desc_ru: Содержит функции для работы с коллекциями
|
||||
since: 2.0.0
|
||||
functions:
|
||||
- name: hashMap
|
||||
args: "fromMap = {}"
|
||||
desc: creates a new HashMap based on `fromMap` values
|
||||
desc_ru: создаёт новый HashMap из значений `fromMap`
|
||||
- name: linkedHashMap
|
||||
args: "fromMap = {}"
|
||||
desc: creates a new LinkedHashMap based on `fromMap` values
|
||||
desc_ru: создаёт новый LinkedHashMap из значений `fromMap`
|
||||
- name: concurrentHashMap
|
||||
args: "fromMap = {}"
|
||||
desc: creates a new ConcurrentHashMap based on `fromMap` values
|
||||
desc_ru: создаёт новый ConcurrentHashMap из значений `fromMap`
|
||||
- name: treeMap
|
||||
args: "fromMap = {}, comparator = def(a, b) = 0"
|
||||
desc: creates a new TreeMap based on `fromMap` values and `comparator`
|
||||
desc_ru: создаёт новый TreeMap из значений `fromMap` и компаратора `comparator`
|
||||
- name: concurrentSkipListMap
|
||||
args: "fromMap = {}, comparator = def(a, b) = 0"
|
||||
desc: creates a new ConcurrentSkipListMap based on `fromMap` values and `comparator`
|
||||
desc_ru: создаёт новый ConcurrentSkipListMap из значений `fromMap` и компаратора `comparator`
|
@ -53,24 +53,14 @@ public class collections implements Module {
|
||||
case 0: // treeMap()
|
||||
map = mapSupplier.get();
|
||||
break;
|
||||
case 1: // treeMap(map) || treeMap(comparator)
|
||||
if (args[0].type() == Types.MAP) {
|
||||
case 1: // treeMap(map)
|
||||
map = mapSupplier.get();
|
||||
map.putAll(((MapValue) args[0]).getMap());
|
||||
} else if (args[0].type() == Types.FUNCTION) {
|
||||
final Function comparator = ValueUtils.consumeFunction(args[0], 0);
|
||||
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
|
||||
} else {
|
||||
throw new TypeException("Map or comparator function expected in first argument");
|
||||
}
|
||||
map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
|
||||
break;
|
||||
case 2: // treeMap(map, comparator)
|
||||
if (args[0].type() != Types.MAP) {
|
||||
throw new TypeException("Map expected in first argument");
|
||||
}
|
||||
final Function comparator = ValueUtils.consumeFunction(args[1], 1);
|
||||
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
|
||||
map.putAll(((MapValue) args[0]).getMap());
|
||||
map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
|
Loading…
Reference in New Issue
Block a user