funcity 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: funcity
3
- * version: 1.1.0
3
+ * version: 1.2.0
4
4
  * description: A functional language interpreter with text processing
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/funcity
8
- * git.commit.hash: bd9ca1189122a6a81cf5363705508020eef87a84
8
+ * git.commit.hash: ef0c333859e785404f4939a0050e42207f7af230
9
9
  */
10
10
 
11
11
  "use strict";
@@ -1949,6 +1949,20 @@ const _cond = makeFunCityFunction(async function(arg0, arg1, arg2) {
1949
1949
  return await this.reduce(arg2);
1950
1950
  }
1951
1951
  });
1952
+ const _defaults = makeFunCityFunction(async function(arg0, arg1, ...rest) {
1953
+ if (!arg0 || !arg1 || rest.length !== 0) {
1954
+ throw new FunCityReducerError({
1955
+ type: "error",
1956
+ description: "Required `defaults` value and default expression",
1957
+ range: this.thisNode.range
1958
+ });
1959
+ }
1960
+ const value = await this.reduce(arg0);
1961
+ if (value !== void 0 && value !== null) {
1962
+ return value;
1963
+ }
1964
+ return await this.reduce(arg1);
1965
+ });
1952
1966
  const _set = makeFunCityFunction(async function(arg0, arg1, ...rest) {
1953
1967
  if (!arg0 || !arg1 || rest.length !== 0) {
1954
1968
  throw new FunCityReducerError({
@@ -2367,6 +2381,18 @@ const _flatMap = async (arg0, arg1) => {
2367
2381
  }
2368
2382
  return resultList;
2369
2383
  };
2384
+ const _flatten = async (arg0) => {
2385
+ const iter = arg0;
2386
+ const resultList = [];
2387
+ for (const item of iter) {
2388
+ const iterable = asIterable(item);
2389
+ if (!iterable) {
2390
+ throw new TypeError("flatten requires nested iterable items");
2391
+ }
2392
+ resultList.push(...iterable);
2393
+ }
2394
+ return resultList;
2395
+ };
2370
2396
  const _filter = async (arg0, arg1) => {
2371
2397
  const predicate = arg0;
2372
2398
  const iter = arg1;
@@ -2810,6 +2836,7 @@ const standardVariables = Object.freeze({
2810
2836
  true: true,
2811
2837
  false: false,
2812
2838
  cond: _cond,
2839
+ defaults: _defaults,
2813
2840
  set: _set,
2814
2841
  fun: _fun,
2815
2842
  toString: _toString,
@@ -2847,6 +2874,7 @@ const standardVariables = Object.freeze({
2847
2874
  reverse: _reverse,
2848
2875
  map: _map,
2849
2876
  flatMap: _flatMap,
2877
+ flatten: _flatten,
2850
2878
  filter: _filter,
2851
2879
  collect: _collect,
2852
2880
  distinct: _distinct,