mol_mutable 0.0.400 → 0.0.402

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/node.deps.json CHANGED
@@ -1 +1 @@
1
- {"files":["mam.ts","LICENSE","README.md","yarn.lock","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/index.html","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/type/README.md","mol/type/immutable/deep/deep/deep.ts","mol/mutable/README.md","mol/mutable/mutable.ts"],"mods":{},"deps_in":{"mol":{"mol/mutable":-9007199254740991,"mol/type":-9007199254740991},"":{"mol":-9007199254740991},"mol/type/immutable/deep/deep":{"mol/mutable":-2},"mol/type/immutable/deep":{"mol/type/immutable/deep/deep":-9007199254740991},"mol/type/immutable":{"mol/type/immutable/deep":-9007199254740991},"mol/type":{"mol/type/immutable":-9007199254740991}},"deps_out":{"mol/mutable":{"mol":-9007199254740991,"mol/type/immutable/deep/deep":-2},"mol":{"":-9007199254740991},"mol/type/immutable/deep/deep":{"mol/type/immutable/deep":-9007199254740991},"mol/type/immutable/deep":{"mol/type/immutable":-9007199254740991},"mol/type/immutable":{"mol/type":-9007199254740991},"mol/type":{"mol":-9007199254740991}},"sloc":{"ts":51,"LICENSE":113,"md":511,"lock":974,"js":9,"json":92,"tree":41,"CNAME":1,"html":1},"deps":{"mol/mutable":{"..":-9007199254740991,"/mol/mutable/wrapper":-1,"/mol/type/immutable/deep":-2,"/mol/mutable":-1},"mol":{"..":-9007199254740991},"":{},"mol/type/immutable/deep/deep":{"..":-9007199254740991,"/mol/type/immutable/deep":-1},"mol/type/immutable/deep":{"..":-9007199254740991},"mol/type/immutable":{"..":-9007199254740991},"mol/type":{"..":-9007199254740991}}}
1
+ {"files":["mam.ts","LICENSE","README.md","yarn.lock","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/index.html","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/type/README.md","mol/type/immutable/deep/deep/deep.ts","mol/mutable/README.md","mol/mutable/mutable.ts"],"mods":{},"deps_in":{"mol":{"mol/mutable":-9007199254740991,"mol/type":-9007199254740991},"":{"mol":-9007199254740991},"mol/type/immutable/deep/deep":{"mol/mutable":-2},"mol/type/immutable/deep":{"mol/type/immutable/deep/deep":-9007199254740991},"mol/type/immutable":{"mol/type/immutable/deep":-9007199254740991},"mol/type":{"mol/type/immutable":-9007199254740991}},"deps_out":{"mol/mutable":{"mol":-9007199254740991,"mol/type/immutable/deep/deep":-2},"mol":{"":-9007199254740991},"mol/type/immutable/deep/deep":{"mol/type/immutable/deep":-9007199254740991},"mol/type/immutable/deep":{"mol/type/immutable":-9007199254740991},"mol/type/immutable":{"mol/type":-9007199254740991},"mol/type":{"mol":-9007199254740991}},"sloc":{"ts":51,"LICENSE":113,"md":511,"lock":974,"js":9,"json":93,"tree":41,"CNAME":1,"html":1},"deps":{"mol/mutable":{"..":-9007199254740991,"/mol/mutable/wrapper":-1,"/mol/type/immutable/deep":-2,"/mol/mutable":-1},"mol":{"..":-9007199254740991},"":{},"mol/type/immutable/deep/deep":{"..":-9007199254740991,"/mol/type/immutable/deep":-1},"mol/type/immutable/deep":{"..":-9007199254740991},"mol/type/immutable":{"..":-9007199254740991},"mol/type":{"..":-9007199254740991}}}
package/node.test.js CHANGED
@@ -693,7 +693,12 @@ var $;
693
693
  var $;
694
694
  (function ($) {
695
695
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
696
- return new Proxy(new $mol_range2_array(), {
696
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
697
+ if (typeof item !== 'function') {
698
+ item = index => source[index];
699
+ size = () => source.length;
700
+ }
701
+ return new Proxy(source, {
697
702
  get(target, field) {
698
703
  if (typeof field === 'string') {
699
704
  if (field === 'length')
@@ -706,7 +711,7 @@ var $;
706
711
  if (index === Math.trunc(index))
707
712
  return item(index);
708
713
  }
709
- return target[field];
714
+ return $mol_range2_array.prototype[field];
710
715
  },
711
716
  set(target, field) {
712
717
  return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
@@ -747,13 +752,16 @@ var $;
747
752
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
748
753
  }
749
754
  filter(check, context) {
750
- const filtered = new $mol_range2_array();
751
- for (let index = 0; index < this.length; ++index) {
752
- const item = this[index];
753
- if (check.call(context, item, index, this))
754
- filtered.push(item);
755
- }
756
- return filtered;
755
+ const filtered = [];
756
+ let cursor = -1;
757
+ return $mol_range2(index => {
758
+ while (cursor < this.length && index >= filtered.length - 1) {
759
+ const val = this[++cursor];
760
+ if (check(val, cursor, this))
761
+ filtered.push(val);
762
+ }
763
+ return filtered[index];
764
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
757
765
  }
758
766
  forEach(proceed, context) {
759
767
  for (let [key, value] of this.entries())
@@ -813,7 +821,7 @@ var $;
813
821
  'lazy calls'() {
814
822
  let calls = 0;
815
823
  const list = $mol_range2(index => (++calls, index), () => 10);
816
- $mol_assert_ok(list instanceof Array);
824
+ $mol_assert_equal(true, list instanceof Array);
817
825
  $mol_assert_equal(list.length, 10);
818
826
  $mol_assert_equal(list[-1], undefined);
819
827
  $mol_assert_equal(list[0], 0);
@@ -856,11 +864,17 @@ var $;
856
864
  $mol_range2(i => i, () => 5).forEach(i => log += i);
857
865
  $mol_assert_equal(log, '01234');
858
866
  },
867
+ 'reduce'() {
868
+ let calls = 0;
869
+ const list = $mol_range2().slice(1, 6);
870
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
871
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
872
+ },
859
873
  'lazy concat'() {
860
874
  let calls1 = 0;
861
875
  let calls2 = 0;
862
876
  const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
863
- $mol_assert_ok(list instanceof Array);
877
+ $mol_assert_equal(true, list instanceof Array);
864
878
  $mol_assert_equal(list.length, 15);
865
879
  $mol_assert_equal(list[0], 0);
866
880
  $mol_assert_equal(list[4], 4);
@@ -872,32 +886,26 @@ var $;
872
886
  $mol_assert_equal(calls1, 2);
873
887
  $mol_assert_equal(calls2, 2);
874
888
  },
875
- 'filter'() {
889
+ 'lazy filter'() {
876
890
  let calls = 0;
877
- const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
878
- $mol_assert_ok(list instanceof Array);
891
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
892
+ $mol_assert_equal(true, list instanceof Array);
879
893
  $mol_assert_equal(list.length, 3);
880
894
  $mol_assert_equal(list[0], 1);
881
895
  $mol_assert_equal(list[2], 5);
882
896
  $mol_assert_equal(list[3], undefined);
883
- $mol_assert_equal(calls, 10);
897
+ $mol_assert_equal(calls, 8);
884
898
  },
885
- 'reverse'() {
899
+ 'lazy reverse'() {
886
900
  let calls = 0;
887
901
  const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
888
- $mol_assert_ok(list instanceof Array);
902
+ $mol_assert_equal(true, list instanceof Array);
889
903
  $mol_assert_equal(list.length, 3);
890
904
  $mol_assert_equal(list[0], 9);
891
905
  $mol_assert_equal(list[2], 7);
892
906
  $mol_assert_equal(list[3], undefined);
893
907
  $mol_assert_equal(calls, 2);
894
908
  },
895
- 'reduce'() {
896
- let calls = 0;
897
- const list = $mol_range2().slice(1, 6);
898
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
899
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
900
- },
901
909
  'lazy map'() {
902
910
  let calls1 = 0;
903
911
  let calls2 = 0;
@@ -907,7 +915,7 @@ var $;
907
915
  $mol_assert_equal(source, self);
908
916
  return index + 10;
909
917
  }, () => 5);
910
- $mol_assert_ok(target instanceof Array);
918
+ $mol_assert_equal(true, target instanceof Array);
911
919
  $mol_assert_equal(target.length, 5);
912
920
  $mol_assert_equal(target[0], 10);
913
921
  $mol_assert_equal(target[4], 14);
@@ -918,7 +926,7 @@ var $;
918
926
  'lazy slice'() {
919
927
  let calls = 0;
920
928
  const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
921
- $mol_assert_ok(list instanceof Array);
929
+ $mol_assert_equal(true, list instanceof Array);
922
930
  $mol_assert_equal(list.length, 4);
923
931
  $mol_assert_equal(list[0], 3);
924
932
  $mol_assert_equal(list[3], 6);
@@ -927,22 +935,22 @@ var $;
927
935
  },
928
936
  'lazy some'() {
929
937
  let calls = 0;
930
- $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
938
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
931
939
  $mol_assert_equal(calls, 3);
932
- $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
933
- $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
940
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
941
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
934
942
  },
935
943
  'lazy every'() {
936
944
  let calls = 0;
937
- $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
945
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
938
946
  $mol_assert_equal(calls, 3);
939
- $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
940
- $mol_assert_not($mol_range2(i => i).every(v => v < 5));
947
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
948
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
941
949
  },
942
950
  'lazyfy'() {
943
951
  let calls = 0;
944
- const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
945
- $mol_assert_ok(list instanceof Array);
952
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
953
+ $mol_assert_equal(true, list instanceof Array);
946
954
  $mol_assert_equal(list.length, 4);
947
955
  $mol_assert_equal(calls, 0);
948
956
  $mol_assert_equal(list[0], 12);