Skip to content

Commit 7366281

Browse files
committed
Add collections documentation
1 parent 02fd959 commit 7366281

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

docs/src/docgen-md.own

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ OUTPUT_PATH_FMT = OUTPUT_DIR_FMT + "/%s.md"
77
LANGS = ["en", "ru"]
88
MODULES = [
99
"std",
10+
"collections",
1011
"date",
1112
"downloader",
1213
"files",

docs/src/modules/collections.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: collections
2+
scope: both
3+
desc: Contains functions for working with collections
4+
desc_ru: Содержит функции для работы с коллекциями
5+
since: 2.0.0
6+
functions:
7+
- name: hashMap
8+
args: "fromMap = {}"
9+
desc: creates a new HashMap based on `fromMap` values
10+
desc_ru: создаёт новый HashMap из значений `fromMap`
11+
- name: linkedHashMap
12+
args: "fromMap = {}"
13+
desc: creates a new LinkedHashMap based on `fromMap` values
14+
desc_ru: создаёт новый LinkedHashMap из значений `fromMap`
15+
- name: concurrentHashMap
16+
args: "fromMap = {}"
17+
desc: creates a new ConcurrentHashMap based on `fromMap` values
18+
desc_ru: создаёт новый ConcurrentHashMap из значений `fromMap`
19+
- name: treeMap
20+
args: "fromMap = {}, comparator = def(a, b) = 0"
21+
desc: creates a new TreeMap based on `fromMap` values and `comparator`
22+
desc_ru: создаёт новый TreeMap из значений `fromMap` и компаратора `comparator`
23+
- name: concurrentSkipListMap
24+
args: "fromMap = {}, comparator = def(a, b) = 0"
25+
desc: creates a new ConcurrentSkipListMap based on `fromMap` values and `comparator`
26+
desc_ru: создаёт новый ConcurrentSkipListMap из значений `fromMap` и компаратора `comparator`

modules/main/src/main/java/com/annimon/ownlang/modules/collections/collections.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,14 @@ private Function sortedMapFunction(final Supplier<SortedMap<Value, Value>> mapSu
5353
case 0: // treeMap()
5454
map = mapSupplier.get();
5555
break;
56-
case 1: // treeMap(map) || treeMap(comparator)
57-
if (args[0].type() == Types.MAP) {
58-
map = mapSupplier.get();
59-
map.putAll(((MapValue) args[0]).getMap());
60-
} else if (args[0].type() == Types.FUNCTION) {
61-
final Function comparator = ValueUtils.consumeFunction(args[0], 0);
62-
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
63-
} else {
64-
throw new TypeException("Map or comparator function expected in first argument");
65-
}
56+
case 1: // treeMap(map)
57+
map = mapSupplier.get();
58+
map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
6659
break;
6760
case 2: // treeMap(map, comparator)
68-
if (args[0].type() != Types.MAP) {
69-
throw new TypeException("Map expected in first argument");
70-
}
7161
final Function comparator = ValueUtils.consumeFunction(args[1], 1);
7262
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
73-
map.putAll(((MapValue) args[0]).getMap());
63+
map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
7464
break;
7565
default:
7666
throw new IllegalStateException();

0 commit comments

Comments
 (0)