Socket
Socket
Sign inDemoInstall

@effect/data

Package Overview
Dependencies
Maintainers
3
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/data - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

45

Chunk.d.ts

@@ -30,47 +30,2 @@ /**

readonly length: number;
get array(): ReadonlyArray<A>;
/**
* @since 1.0.0
*/
toReadonlyArray(this: Chunk<A>): ReadonlyArray<A>;
/**
* @since 1.0.0
*/
isNonEmpty(this: Chunk<A>): this is NonEmptyChunk<A>;
/**
* @since 1.0.0
*/
isEmpty(this: Chunk<A>): boolean;
/**
* @since 1.0.0
*/
map<B>(this: Chunk<A>, f: (a: A) => B): Chunk<B>;
/**
* @since 1.0.0
*/
flatMap<B>(this: Chunk<A>, f: (a: A) => Chunk<B>): Chunk<B>;
/**
* @since 1.0.0
*/
forEach(this: Chunk<A>, f: (a: A) => void): void;
/**
* @since 1.0.0
*/
append<B>(this: Chunk<A>, b: B): Chunk<A | B>;
/**
* @since 1.0.0
*/
prepend<B>(this: Chunk<A>, b: B): Chunk<A | B>;
/**
* @since 1.0.0
*/
concat<B>(this: Chunk<A>, that: Chunk<B>): Chunk<A | B>;
/**
* @since 1.0.0
*/
get(this: Chunk<A>, index: number): Option<A>;
/**
* @since 1.0.0
*/
unsafeGet(this: Chunk<A>, index: number): A;
}

@@ -77,0 +32,0 @@ /**

333

Chunk.js

@@ -64,32 +64,4 @@ "use strict";

}
get array() {
return this.toReadonlyArray();
}
toReadonlyArray() {
switch (this.backing._tag) {
case "IEmpty":
{
return emptyArray;
}
case "IArray":
{
return this.backing.array;
}
default:
{
const arr = new Array(this.length);
copyToArray(this, arr, 0);
this.backing = {
_tag: "IArray",
array: arr
};
this.left = _empty;
this.right = _empty;
this.depth = 0;
return arr;
}
}
}
toString() {
return `Chunk(${this.toReadonlyArray().map(String).join(", ")})`;
return `Chunk(${toReadonlyArray(this).map(String).join(", ")})`;
}

@@ -99,3 +71,3 @@ toJSON() {

_tag: "Chunk",
values: this.toReadonlyArray()
values: toReadonlyArray(this)
};

@@ -106,146 +78,5 @@ }

}
isNonEmpty() {
return this.length > 0;
}
isEmpty() {
return !this.isNonEmpty();
}
map(f) {
return this.backing._tag === "ISingleton" ? of(f(this.backing.a)) : unsafeFromArray(RA.map(f)(toReadonlyArray(this)));
}
flatMap(f) {
if (this.backing._tag === "ISingleton") {
return f(this.backing.a);
}
let r = _empty;
for (const k of this) {
r = concat(f(k))(r);
}
return r;
}
forEach(f) {
return this.backing._tag === "ISingleton" ? f(this.backing.a) : toReadonlyArray(this).forEach(f);
}
append(b) {
return this.concat(of(b));
}
prepend(b) {
return of(b).concat(this);
}
concat(that) {
if (this.backing._tag === "IEmpty") {
return that;
}
if (that.backing._tag === "IEmpty") {
return this;
}
const diff = that.depth - this.depth;
if (Math.abs(diff) <= 1) {
return new ChunkImpl({
_tag: "IConcat",
left: this,
right: that
});
} else if (diff < -1) {
if (this.left.depth >= this.right.depth) {
const nr = concat(that)(this.right);
return new ChunkImpl({
_tag: "IConcat",
left: this.left,
right: nr
});
} else {
const nrr = concat(that)(this.right.right);
if (nrr.depth === this.depth - 3) {
const nr = new ChunkImpl({
_tag: "IConcat",
left: this.right.left,
right: nrr
});
return new ChunkImpl({
_tag: "IConcat",
left: this.left,
right: nr
});
} else {
const nl = new ChunkImpl({
_tag: "IConcat",
left: this.left,
right: this.right.left
});
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: nrr
});
}
}
} else {
if (that.right.depth >= that.left.depth) {
const nl = concat(that.left)(this);
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: that.right
});
} else {
const nll = concat(that.left.left)(this);
if (nll.depth === that.depth - 3) {
const nl = new ChunkImpl({
_tag: "IConcat",
left: nll,
right: that.left.right
});
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: that.right
});
} else {
const nr = new ChunkImpl({
_tag: "IConcat",
left: that.left.right,
right: that.right
});
return new ChunkImpl({
_tag: "IConcat",
left: nll,
right: nr
});
}
}
}
}
get(index) {
return index < 0 || index >= this.length ? O.none() : O.some(this.unsafeGet(index));
}
unsafeGet(index) {
switch (this.backing._tag) {
case "IEmpty":
{
throw new Error(`Index out of bounds`);
}
case "ISingleton":
{
if (index !== 0) {
throw new Error(`Index out of bounds`);
}
return this.backing.a;
}
case "IArray":
{
if (index >= this.length || index < 0) {
throw new Error(`Index out of bounds`);
}
return this.backing.array[index];
}
case "IConcat":
{
return index < this.left.length ? this.left.unsafeGet(index) : this.right.unsafeGet(index - this.left.length);
}
}
}
[Equal.symbol](that) {
if (isChunk(that) && this.length === that.length) {
return toReadonlyArray(this).every((value, i) => Equal.equals(value, that.unsafeGet(i)));
return toReadonlyArray(this).every((value, i) => Equal.equals(value, unsafeGet(that, i)));
}

@@ -329,3 +160,27 @@ return false;

exports.fromIterable = fromIterable;
const toReadonlyArray = self => self.toReadonlyArray();
const toReadonlyArray = self => {
switch (self.backing._tag) {
case "IEmpty":
{
return emptyArray;
}
case "IArray":
{
return self.backing.array;
}
default:
{
const arr = new Array(self.length);
copyToArray(self, arr, 0);
self.backing = {
_tag: "IArray",
array: arr
};
self.left = _empty;
self.right = _empty;
self.depth = 0;
return arr;
}
}
};
/**

@@ -338,3 +193,3 @@ * This function provides a safe way to read a value at a particular index from a `Chunk`.

exports.toReadonlyArray = toReadonlyArray;
const get = /*#__PURE__*/Dual.dual(2, (self, index) => self.get(index));
const get = /*#__PURE__*/Dual.dual(2, (self, index) => index < 0 || index >= self.length ? O.none() : O.some(unsafeGet(self, index)));
/**

@@ -358,3 +213,28 @@ * Wraps an array into a chunk without copying, unsafe on mutable arrays

exports.unsafeFromArray = unsafeFromArray;
const unsafeGet = /*#__PURE__*/Dual.dual(2, (self, index) => self.unsafeGet(index));
const unsafeGet = /*#__PURE__*/Dual.dual(2, (self, index) => {
switch (self.backing._tag) {
case "IEmpty":
{
throw new Error(`Index out of bounds`);
}
case "ISingleton":
{
if (index !== 0) {
throw new Error(`Index out of bounds`);
}
return self.backing.a;
}
case "IArray":
{
if (index >= self.length || index < 0) {
throw new Error(`Index out of bounds`);
}
return self.backing.array[index];
}
case "IConcat":
{
return index < self.left.length ? unsafeGet(self.left, index) : unsafeGet(self.right, index - self.left.length);
}
}
});
/**

@@ -367,3 +247,3 @@ * Appends the value to the chunk

exports.unsafeGet = unsafeGet;
const append = /*#__PURE__*/Dual.dual(2, (self, a) => self.append(a));
const append = /*#__PURE__*/Dual.dual(2, (self, a) => concat(self, of(a)));
/**

@@ -376,3 +256,3 @@ * Prepends the value to the chunk

exports.append = append;
const prepend = /*#__PURE__*/Dual.dual(2, (self, elem) => self.prepend(elem));
const prepend = /*#__PURE__*/Dual.dual(2, (self, a) => concat(of(a), self));
/**

@@ -391,3 +271,3 @@ * Takes the first up to `n` elements from the chunk

} else {
return unsafeFromArray(RA.take(n)(self.toReadonlyArray()));
return unsafeFromArray(RA.take(n)(toReadonlyArray(self)));
}

@@ -408,3 +288,3 @@ });

} else {
return unsafeFromArray(RA.drop(n)(self.toReadonlyArray()));
return unsafeFromArray(RA.drop(n)(toReadonlyArray(self)));
}

@@ -441,3 +321,3 @@ });

exports.dropWhile = dropWhile;
const prependAllNonEmpty = /*#__PURE__*/Dual.dual(2, (self, that) => that.concat(self));
const prependAllNonEmpty = /*#__PURE__*/Dual.dual(2, (self, that) => concat(that, self));
/**

@@ -450,3 +330,86 @@ * Concatenates the two chunks

exports.prependAllNonEmpty = prependAllNonEmpty;
const concat = /*#__PURE__*/Dual.dual(2, (self, that) => self.concat(that));
const concat = /*#__PURE__*/Dual.dual(2, (self, that) => {
if (self.backing._tag === "IEmpty") {
return that;
}
if (that.backing._tag === "IEmpty") {
return self;
}
const diff = that.depth - self.depth;
if (Math.abs(diff) <= 1) {
return new ChunkImpl({
_tag: "IConcat",
left: self,
right: that
});
} else if (diff < -1) {
if (self.left.depth >= self.right.depth) {
const nr = concat(that)(self.right);
return new ChunkImpl({
_tag: "IConcat",
left: self.left,
right: nr
});
} else {
const nrr = concat(that)(self.right.right);
if (nrr.depth === self.depth - 3) {
const nr = new ChunkImpl({
_tag: "IConcat",
left: self.right.left,
right: nrr
});
return new ChunkImpl({
_tag: "IConcat",
left: self.left,
right: nr
});
} else {
const nl = new ChunkImpl({
_tag: "IConcat",
left: self.left,
right: self.right.left
});
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: nrr
});
}
}
} else {
if (that.right.depth >= that.left.depth) {
const nl = concat(that.left)(self);
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: that.right
});
} else {
const nll = concat(that.left.left)(self);
if (nll.depth === that.depth - 3) {
const nl = new ChunkImpl({
_tag: "IConcat",
left: nll,
right: that.left.right
});
return new ChunkImpl({
_tag: "IConcat",
left: nl,
right: that.right
});
} else {
const nr = new ChunkImpl({
_tag: "IConcat",
left: that.left.right,
right: that.right
});
return new ChunkImpl({
_tag: "IConcat",
left: nll,
right: nr
});
}
}
}
});
/**

@@ -624,3 +587,3 @@ * Compares the two chunks of equal length using the specified function

exports.flatten = flatten;
const forEach = /*#__PURE__*/Dual.dual(2, (self, f) => self.forEach(f));
const forEach = /*#__PURE__*/Dual.dual(2, (self, f) => self.backing._tag === "ISingleton" ? f(self.backing.a) : toReadonlyArray(self).forEach(f));
/**

@@ -673,3 +636,3 @@ * Groups elements in chunks of up to `n` elements.

exports.intersection = intersection;
const isEmpty = self => self.isEmpty();
const isEmpty = self => self.length === 0;
/**

@@ -682,3 +645,3 @@ * Determines if the chunk is not empty.

exports.isEmpty = isEmpty;
const isNonEmpty = self => self.isNonEmpty();
const isNonEmpty = self => self.length > 0;
/**

@@ -768,3 +731,3 @@ * Folds over the elements in this chunk from the left.

exports.makeBy = makeBy;
const map = /*#__PURE__*/Dual.dual(2, (self, f) => self.map(f));
const map = /*#__PURE__*/Dual.dual(2, (self, f) => self.backing._tag === "ISingleton" ? of(f(self.backing.a)) : unsafeFromArray(RA.map(f)(toReadonlyArray(self))));
/**

@@ -771,0 +734,0 @@ * Returns an effect whose success is mapped by the specified f function.

@@ -91,5 +91,7 @@ "use strict";

// @ts-expect-error
args => args === undefined ? struct({}) : struct({
_tag: tag,
...args
args => args === undefined ? struct({
_tag: tag
}) : struct({
...args,
_tag: tag
});

@@ -96,0 +98,0 @@ /**

@@ -7,5 +7,5 @@ "use strict";

exports.size = exports.set = exports.remove = exports.modifyAt = exports.modify = exports.make = exports.has = exports.get = exports.fromIterable = exports.empty = void 0;
var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Equal"));
var Dual = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Function"));
var Hash = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Hash"));
var HashMap = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/HashMap"));
var MutableRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/MutableRef"));
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));

@@ -20,49 +20,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

/** @internal */
class Node {
constructor(k, v, next) {
this.k = k;
this.v = v;
this.next = next;
}
[Symbol.iterator]() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let c = this;
let n = 0;
return {
next: () => {
if (c) {
const kv = [c.k, c.v];
c = c.next;
n++;
return {
value: kv,
done: false
};
} else {
return {
value: n,
done: true
};
}
}
};
}
}
/** @internal */
class MutableHashMapImpl {
constructor() {
this._id = TypeId;
this.backingMap = new Map();
this.length = 0;
this.backingMap = MutableRef.make(HashMap.empty());
}
[Symbol.iterator]() {
return Array.from(this.backingMap.values()).flatMap(node => {
const arr = [[node.k, node.v]];
let next = node.next;
while (next) {
arr.push([next.k, next.v]);
next = next.next;
}
return arr;
})[Symbol.iterator]();
return this.backingMap.current[Symbol.iterator]();
}

@@ -110,17 +70,3 @@ toString() {

exports.fromIterable = fromIterable;
const get = /*#__PURE__*/Dual.dual(2, (self, key) => {
const hash = Hash.hash(key);
const arr = self.backingMap.get(hash);
if (arr === undefined) {
return Option.none();
}
let c = arr;
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
return Option.some(c.v);
}
c = c.next;
}
return Option.none();
});
const get = /*#__PURE__*/Dual.dual(2, (self, key) => HashMap.get(self.backingMap.current, key));
/**

@@ -140,15 +86,3 @@ * @since 1.0.0

const modify = /*#__PURE__*/Dual.dual(3, (self, key, f) => {
const hash = Hash.hash(key);
const arr = self.backingMap.get(hash);
if (arr === undefined) {
return self;
}
let c = arr;
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
c.v = f(c.v);
return self;
}
c = c.next;
}
MutableRef.update(self.backingMap, HashMap.modify(key, f));
return self;

@@ -179,27 +113,3 @@ });

const remove = /*#__PURE__*/Dual.dual(2, (self, key) => {
const hash = Hash.hash(key);
const arr = self.backingMap.get(hash);
if (arr === undefined) {
return self;
}
if (Equal.equals(key, arr.k)) {
if (arr.next !== undefined) {
self.backingMap.set(hash, arr.next);
} else {
self.backingMap.delete(hash);
}
self.length = self.length - 1;
return self;
}
let next = arr.next;
let curr = arr;
while (next !== undefined) {
if (Equal.equals(key, next.k)) {
curr.next = next.next;
self.length = self.length - 1;
return self;
}
curr = next;
next = next.next;
}
MutableRef.update(self.backingMap, HashMap.remove(key));
return self;

@@ -213,21 +123,3 @@ });

const set = /*#__PURE__*/Dual.dual(3, (self, key, value) => {
const hash = Hash.hash(key);
const arr = self.backingMap.get(hash);
if (arr === undefined) {
self.backingMap.set(hash, new Node(key, value));
self.length = self.length + 1;
return self;
}
let c = arr;
let l = arr;
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
c.v = value;
return self;
}
l = c;
c = c.next;
}
self.length = self.length + 1;
l.next = new Node(key, value);
MutableRef.update(self.backingMap, HashMap.set(key, value));
return self;

@@ -240,4 +132,4 @@ });

exports.set = set;
const size = self => self.length;
const size = self => HashMap.size(MutableRef.get(self.backingMap));
exports.size = size;
//# sourceMappingURL=MutableHashMap.js.map

@@ -23,5 +23,2 @@ "use strict";

}
get length() {
return this.keyMap.length;
}
[Symbol.iterator]() {

@@ -28,0 +25,0 @@ return Array.from(this.keyMap).map(([_]) => _)[Symbol.iterator]();

@@ -14,47 +14,2 @@ declare const TypeId: unique symbol;

readonly _T: (_: never) => T;
/**
* @since 1.0.0
* @category general
*/
get<T>(this: MutableRef<T>): T;
/**
* @since 1.0.0
* @category general
*/
set<T>(this: MutableRef<T>, value: T): MutableRef<T>;
/**
* @since 1.0.0
* @category general
*/
update<T>(this: MutableRef<T>, f: (value: T) => T): MutableRef<T>;
/**
* @since 1.0.0
* @category general
*/
updateAndGet<T>(this: MutableRef<T>, f: (value: T) => T): T;
/**
* @since 1.0.0
* @category general
*/
getAndUpdate<T>(this: MutableRef<T>, f: (value: T) => T): T;
/**
* @since 1.0.0
* @category general
*/
setAndGet<T>(this: MutableRef<T>, value: T): T;
/**
* @since 1.0.0
* @category general
*/
getAndSet<T>(this: MutableRef<T>, value: T): T;
/**
* @since 1.0.0
* @category general
*/
compareAndSet<T>(this: MutableRef<T>, oldValue: T, newValue: T): boolean;
/**
* @since 1.0.0
* @category general
*/
pipe<T, B>(this: MutableRef<T>, f: (_: MutableRef<T>) => B): B;
}

@@ -61,0 +16,0 @@ /**

@@ -22,37 +22,2 @@ "use strict";

}
get() {
return this.current;
}
set(value) {
this.current = value;
return this;
}
setAndGet(value) {
this.current = value;
return this.current;
}
getAndSet(value) {
const ret = this.current;
this.current = value;
return ret;
}
compareAndSet(oldValue, newValue) {
if (Equal.equals(oldValue, this.current)) {
this.current = newValue;
return true;
}
return false;
}
pipe(f) {
return f(this);
}
update(f) {
return this.set(f(this.get()));
}
updateAndGet(f) {
return this.setAndGet(f(this.get()));
}
getAndUpdate(f) {
return this.getAndSet(f(this.get()));
}
toString() {

@@ -81,3 +46,9 @@ return `MutableRef(${String(this.current)})`;

exports.make = make;
const compareAndSet = /*#__PURE__*/Dual.dual(3, (self, oldValue, newValue) => self.compareAndSet(oldValue, newValue));
const compareAndSet = /*#__PURE__*/Dual.dual(3, (self, oldValue, newValue) => {
if (Equal.equals(oldValue, self.current)) {
self.current = newValue;
return true;
}
return false;
});
/**

@@ -88,3 +59,3 @@ * @since 1.0.0

exports.compareAndSet = compareAndSet;
const decrement = self => self.update(n => n - 1);
const decrement = self => update(self, n => n - 1);
/**

@@ -95,3 +66,3 @@ * @since 1.0.0

exports.decrement = decrement;
const decrementAndGet = self => self.updateAndGet(n => n - 1);
const decrementAndGet = self => updateAndGet(self, n => n - 1);
/**

@@ -108,3 +79,3 @@ * @since 1.0.0

exports.get = get;
const getAndDecrement = self => self.getAndUpdate(n => n - 1);
const getAndDecrement = self => getAndUpdate(self, n => n - 1);
/**

@@ -115,3 +86,3 @@ * @since 1.0.0

exports.getAndDecrement = getAndDecrement;
const getAndIncrement = self => self.getAndUpdate(n => n + 1);
const getAndIncrement = self => getAndUpdate(self, n => n + 1);
/**

@@ -122,3 +93,7 @@ * @since 1.0.0

exports.getAndIncrement = getAndIncrement;
const getAndSet = /*#__PURE__*/Dual.dual(2, (self, value) => self.getAndSet(value));
const getAndSet = /*#__PURE__*/Dual.dual(2, (self, value) => {
const ret = self.current;
self.current = value;
return ret;
});
/**

@@ -129,3 +104,3 @@ * @since 1.0.0

exports.getAndSet = getAndSet;
const getAndUpdate = /*#__PURE__*/Dual.dual(2, (self, f) => self.getAndUpdate(f));
const getAndUpdate = /*#__PURE__*/Dual.dual(2, (self, f) => getAndSet(self, f(get(self))));
/**

@@ -136,3 +111,3 @@ * @since 1.0.0

exports.getAndUpdate = getAndUpdate;
const increment = self => self.update(n => n + 1);
const increment = self => update(self, n => n + 1);
/**

@@ -143,3 +118,3 @@ * @since 1.0.0

exports.increment = increment;
const incrementAndGet = self => self.updateAndGet(n => n + 1);
const incrementAndGet = self => updateAndGet(self, n => n + 1);
/**

@@ -150,3 +125,6 @@ * @since 1.0.0

exports.incrementAndGet = incrementAndGet;
const set = /*#__PURE__*/Dual.dual(2, (self, value) => self.set(value));
const set = /*#__PURE__*/Dual.dual(2, (self, value) => {
self.current = value;
return self;
});
/**

@@ -157,3 +135,6 @@ * @since 1.0.0

exports.set = set;
const setAndGet = /*#__PURE__*/Dual.dual(2, (self, value) => self.setAndGet(value));
const setAndGet = /*#__PURE__*/Dual.dual(2, (self, value) => {
self.current = value;
return self.current;
});
/**

@@ -164,3 +145,3 @@ * @since 1.0.0

exports.setAndGet = setAndGet;
const update = /*#__PURE__*/Dual.dual(2, (self, f) => self.update(f));
const update = /*#__PURE__*/Dual.dual(2, (self, f) => set(self, f(get(self))));
/**

@@ -171,3 +152,3 @@ * @since 1.0.0

exports.update = update;
const updateAndGet = /*#__PURE__*/Dual.dual(2, (self, f) => self.updateAndGet(f));
const updateAndGet = /*#__PURE__*/Dual.dual(2, (self, f) => setAndGet(self, f(get(self))));
/**

@@ -178,4 +159,4 @@ * @since 1.0.0

exports.updateAndGet = updateAndGet;
const toggle = self => self.update(_ => !_);
const toggle = self => update(self, _ => !_);
exports.toggle = toggle;
//# sourceMappingURL=MutableRef.js.map
{
"name": "@effect/data",
"version": "0.3.3",
"version": "0.4.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "repository": {

@@ -48,59 +48,2 @@ /**

depth: number
get array(): ReadonlyArray<A>
/**
* @since 1.0.0
*/
toReadonlyArray(this: Chunk<A>): ReadonlyArray<A>
/**
* @since 1.0.0
*/
isNonEmpty(this: Chunk<A>): this is NonEmptyChunk<A>
/**
* @since 1.0.0
*/
isEmpty(this: Chunk<A>): boolean
/**
* @since 1.0.0
*/
map<B>(this: Chunk<A>, f: (a: A) => B): Chunk<B>
/**
* @since 1.0.0
*/
flatMap<B>(this: Chunk<A>, f: (a: A) => Chunk<B>): Chunk<B>
/**
* @since 1.0.0
*/
forEach(this: Chunk<A>, f: (a: A) => void): void
/**
* @since 1.0.0
*/
append<B>(this: Chunk<A>, b: B): Chunk<A | B>
/**
* @since 1.0.0
*/
prepend<B>(this: Chunk<A>, b: B): Chunk<A | B>
/**
* @since 1.0.0
*/
concat<B>(this: Chunk<A>, that: Chunk<B>): Chunk<A | B>
/**
* @since 1.0.0
*/
get(this: Chunk<A>, index: number): Option<A>
/**
* @since 1.0.0
*/
unsafeGet(this: Chunk<A>, index: number): A
}

@@ -206,31 +149,4 @@

get array(): ReadonlyArray<A> {
return this.toReadonlyArray()
}
toReadonlyArray(this: Chunk<A>): ReadonlyArray<A> {
switch (this.backing._tag) {
case "IEmpty": {
return emptyArray
}
case "IArray": {
return this.backing.array
}
default: {
const arr = new Array<A>(this.length)
copyToArray(this, arr, 0)
this.backing = {
_tag: "IArray",
array: arr
}
this.left = _empty
this.right = _empty
this.depth = 0
return arr
}
}
}
toString() {
return `Chunk(${this.toReadonlyArray().map(String).join(", ")})`
return `Chunk(${toReadonlyArray(this).map(String).join(", ")})`
}

@@ -241,3 +157,3 @@

_tag: "Chunk",
values: this.toReadonlyArray()
values: toReadonlyArray(this)
}

@@ -250,114 +166,5 @@ }

isNonEmpty(this: Chunk<A>): this is NonEmptyChunk<A> {
return this.length > 0
}
isEmpty(this: Chunk<A>): boolean {
return !this.isNonEmpty()
}
map<B>(this: Chunk<A>, f: (a: A) => B): Chunk<B> {
return this.backing._tag === "ISingleton" ?
of(f(this.backing.a)) :
unsafeFromArray(RA.map(f)(toReadonlyArray(this)))
}
flatMap<B>(this: Chunk<A>, f: (a: A) => Chunk<B>): Chunk<B> {
if (this.backing._tag === "ISingleton") {
return f(this.backing.a)
}
let r: Chunk<B> = _empty
for (const k of this) {
r = concat(f(k))(r)
}
return r
}
forEach(this: Chunk<A>, f: (a: A) => void): void {
return this.backing._tag === "ISingleton" ?
f(this.backing.a) :
toReadonlyArray(this).forEach(f)
}
append<B>(this: Chunk<A>, b: B): Chunk<A | B> {
return this.concat(of(b))
}
prepend<B>(this: Chunk<A>, b: B): Chunk<A | B> {
return of(b).concat(this)
}
concat<B>(this: Chunk<A>, that: Chunk<B>): Chunk<A | B> {
if (this.backing._tag === "IEmpty") {
return that
}
if (that.backing._tag === "IEmpty") {
return this
}
const diff = that.depth - this.depth
if (Math.abs(diff) <= 1) {
return new ChunkImpl<A | B>({ _tag: "IConcat", left: this, right: that })
} else if (diff < -1) {
if (this.left.depth >= this.right.depth) {
const nr = concat(that)(this.right)
return new ChunkImpl({ _tag: "IConcat", left: this.left, right: nr })
} else {
const nrr = concat(that)(this.right.right)
if (nrr.depth === this.depth - 3) {
const nr = new ChunkImpl({ _tag: "IConcat", left: this.right.left, right: nrr })
return new ChunkImpl({ _tag: "IConcat", left: this.left, right: nr })
} else {
const nl = new ChunkImpl({ _tag: "IConcat", left: this.left, right: this.right.left })
return new ChunkImpl({ _tag: "IConcat", left: nl, right: nrr })
}
}
} else {
if (that.right.depth >= that.left.depth) {
const nl = concat(that.left)(this)
return new ChunkImpl({ _tag: "IConcat", left: nl, right: that.right })
} else {
const nll = concat(that.left.left)(this)
if (nll.depth === that.depth - 3) {
const nl = new ChunkImpl({ _tag: "IConcat", left: nll, right: that.left.right })
return new ChunkImpl({ _tag: "IConcat", left: nl, right: that.right })
} else {
const nr = new ChunkImpl({ _tag: "IConcat", left: that.left.right, right: that.right })
return new ChunkImpl({ _tag: "IConcat", left: nll, right: nr })
}
}
}
}
get(this: Chunk<A>, index: number): Option<A> {
return index < 0 || index >= this.length ? O.none() : O.some(this.unsafeGet(index))
}
unsafeGet(this: Chunk<A>, index: number): A {
switch (this.backing._tag) {
case "IEmpty": {
throw new Error(`Index out of bounds`)
}
case "ISingleton": {
if (index !== 0) {
throw new Error(`Index out of bounds`)
}
return this.backing.a
}
case "IArray": {
if (index >= this.length || index < 0) {
throw new Error(`Index out of bounds`)
}
return this.backing.array[index]!
}
case "IConcat": {
return index < this.left.length
? this.left.unsafeGet(index)
: this.right.unsafeGet(index - this.left.length)
}
}
}
[Equal.symbol](that: unknown): boolean {
if (isChunk(that) && this.length === that.length) {
return toReadonlyArray(this).every((value, i) => Equal.equals(value, that.unsafeGet(i)))
return toReadonlyArray(this).every((value, i) => Equal.equals(value, unsafeGet(that, i)))
}

@@ -444,3 +251,24 @@ return false

*/
export const toReadonlyArray = <A>(self: Chunk<A>): ReadonlyArray<A> => self.toReadonlyArray()
export const toReadonlyArray = <A>(self: Chunk<A>): ReadonlyArray<A> => {
switch (self.backing._tag) {
case "IEmpty": {
return emptyArray
}
case "IArray": {
return self.backing.array
}
default: {
const arr = new Array<A>(self.length)
copyToArray(self, arr, 0)
self.backing = {
_tag: "IArray",
array: arr
}
self.left = _empty
self.right = _empty
self.depth = 0
return arr
}
}
}

@@ -459,3 +287,3 @@ /**

<A>(self: Chunk<A>, index: number) => Option<A>
>(2, (self, index) => self.get(index))
>(2, (self, index) => index < 0 || index >= self.length ? O.none() : O.some(unsafeGet(self, index)))

@@ -482,3 +310,26 @@ /**

<A>(self: Chunk<A>, index: number) => A
>(2, (self, index) => self.unsafeGet(index))
>(2, (self, index) => {
switch (self.backing._tag) {
case "IEmpty": {
throw new Error(`Index out of bounds`)
}
case "ISingleton": {
if (index !== 0) {
throw new Error(`Index out of bounds`)
}
return self.backing.a
}
case "IArray": {
if (index >= self.length || index < 0) {
throw new Error(`Index out of bounds`)
}
return self.backing.array[index]!
}
case "IConcat": {
return index < self.left.length
? unsafeGet(self.left, index)
: unsafeGet(self.right, index - self.left.length)
}
}
})

@@ -497,3 +348,3 @@ /**

<A, A2>(self: Chunk<A>, a: A2) => Chunk<A | A2>
>(2, (self, a) => self.append(a))
>(2, (self, a) => concat(self, of(a)))

@@ -512,3 +363,3 @@ /**

<A, B>(self: Chunk<A>, elem: B) => Chunk<A | B>
>(2, (self, elem) => self.prepend(elem))
>(2, (self, a) => concat(of(a), self))

@@ -533,3 +384,3 @@ /**

} else {
return unsafeFromArray(RA.take(n)(self.toReadonlyArray()))
return unsafeFromArray(RA.take(n)(toReadonlyArray(self)))
}

@@ -556,3 +407,3 @@ })

} else {
return unsafeFromArray(RA.drop(n)(self.toReadonlyArray()))
return unsafeFromArray(RA.drop(n)(toReadonlyArray(self)))
}

@@ -615,3 +466,3 @@ })

}
>(2, (self, that) => that.concat(self) as any)
>(2, (self, that) => concat(that, self) as any)

@@ -630,3 +481,42 @@ /**

<A, B>(self: Chunk<A>, that: Chunk<B>) => Chunk<A | B>
>(2, (self, that) => self.concat(that))
>(2, <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B> => {
if (self.backing._tag === "IEmpty") {
return that
}
if (that.backing._tag === "IEmpty") {
return self
}
const diff = that.depth - self.depth
if (Math.abs(diff) <= 1) {
return new ChunkImpl<A | B>({ _tag: "IConcat", left: self, right: that })
} else if (diff < -1) {
if (self.left.depth >= self.right.depth) {
const nr = concat(that)(self.right)
return new ChunkImpl({ _tag: "IConcat", left: self.left, right: nr })
} else {
const nrr = concat(that)(self.right.right)
if (nrr.depth === self.depth - 3) {
const nr = new ChunkImpl({ _tag: "IConcat", left: self.right.left, right: nrr })
return new ChunkImpl({ _tag: "IConcat", left: self.left, right: nr })
} else {
const nl = new ChunkImpl({ _tag: "IConcat", left: self.left, right: self.right.left })
return new ChunkImpl({ _tag: "IConcat", left: nl, right: nrr })
}
}
} else {
if (that.right.depth >= that.left.depth) {
const nl = concat(that.left)(self)
return new ChunkImpl({ _tag: "IConcat", left: nl, right: that.right })
} else {
const nll = concat(that.left.left)(self)
if (nll.depth === that.depth - 3) {
const nl = new ChunkImpl({ _tag: "IConcat", left: nll, right: that.left.right })
return new ChunkImpl({ _tag: "IConcat", left: nl, right: that.right })
} else {
const nr = new ChunkImpl({ _tag: "IConcat", left: that.left.right, right: that.right })
return new ChunkImpl({ _tag: "IConcat", left: nll, right: nr })
}
}
}
})

@@ -916,3 +806,6 @@ /**

<A>(self: Chunk<A>, f: (a: A) => void) => void
>(2, (self, f) => self.forEach(f))
>(2, (self, f) =>
self.backing._tag === "ISingleton" ?
f(self.backing.a) :
toReadonlyArray(self).forEach(f))

@@ -982,3 +875,3 @@ /**

*/
export const isEmpty = <A>(self: Chunk<A>): boolean => self.isEmpty()
export const isEmpty = <A>(self: Chunk<A>): boolean => self.length === 0

@@ -991,3 +884,3 @@ /**

*/
export const isNonEmpty = <A>(self: Chunk<A>): self is NonEmptyChunk<A> => self.isNonEmpty()
export const isNonEmpty = <A>(self: Chunk<A>): self is NonEmptyChunk<A> => self.length > 0

@@ -1118,3 +1011,6 @@ /**

<A, B>(self: Chunk<A>, f: (a: A) => B) => Chunk<B>
>(2, (self, f) => self.map(f))
>(2, (self, f) =>
self.backing._tag === "ISingleton" ?
of(f(self.backing.a)) :
unsafeFromArray(RA.map(f)(toReadonlyArray(self))))

@@ -1121,0 +1017,0 @@ /**

@@ -128,3 +128,3 @@ /**

// @ts-expect-error
(args) => args === undefined ? struct({}) : struct({ _tag: tag, ...args })
(args) => args === undefined ? struct({ _tag: tag }) : struct({ ...args, _tag: tag })

@@ -131,0 +131,0 @@ /**

/**
* @since 1.0.0
*/
import * as Equal from "@effect/data/Equal"
import * as Dual from "@effect/data/Function"
import * as Hash from "@effect/data/Hash"
import * as HashMap from "@effect/data/HashMap"
import * as MutableRef from "@effect/data/MutableRef"
import * as Option from "@effect/data/Option"

@@ -17,31 +17,2 @@

/** @internal */
class Node<K, V> implements Iterable<readonly [K, V]> {
constructor(readonly k: K, public v: V, public next?: Node<K, V>) {}
[Symbol.iterator](): Iterator<readonly [K, V]> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let c: Node<K, V> | undefined = this
let n = 0
return {
next: () => {
if (c) {
const kv = [c.k, c.v] as const
c = c.next
n++
return {
value: kv,
done: false
}
} else {
return {
value: n,
done: true
}
}
}
}
}
}
/**

@@ -55,5 +26,3 @@ * @since 1.0.0

/** @internal */
readonly backingMap: Map<number, Node<K, V>>
/** @internal */
length: number
readonly backingMap: MutableRef.MutableRef<HashMap.HashMap<K, V>>
}

@@ -65,17 +34,6 @@

readonly backingMap = new Map<number, Node<K, V>>()
readonly backingMap = MutableRef.make(HashMap.empty());
length = 0;
[Symbol.iterator](): Iterator<readonly [K, V]> {
return Array.from(this.backingMap.values())
.flatMap((node) => {
const arr = [[node.k, node.v] as const]
let next = node.next
while (next) {
arr.push([next.k, next.v])
next = next.next
}
return arr
})[Symbol.iterator]()
return this.backingMap.current[Symbol.iterator]()
}

@@ -138,17 +96,3 @@

<K, V>(self: MutableHashMap<K, V>, key: K) => Option.Option<V>
>(2, <K, V>(self: MutableHashMap<K, V>, key: K) => {
const hash = Hash.hash(key)
const arr = self.backingMap.get(hash)
if (arr === undefined) {
return Option.none()
}
let c: Node<K, V> | undefined = arr
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
return Option.some(c.v)
}
c = c.next
}
return Option.none()
})
>(2, <K, V>(self: MutableHashMap<K, V>, key: K) => HashMap.get(self.backingMap.current, key))

@@ -179,18 +123,9 @@ /**

<K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V) => MutableHashMap<K, V>
>(3, <K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V) => {
const hash = Hash.hash(key)
const arr = self.backingMap.get(hash)
if (arr === undefined) {
>(
3,
<K, V>(self: MutableHashMap<K, V>, key: K, f: (v: V) => V) => {
MutableRef.update(self.backingMap, HashMap.modify(key, f))
return self
}
let c: Node<K, V> | undefined = arr
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
c.v = f(c.v)
return self
}
c = c.next
}
return self
})
)

@@ -238,27 +173,3 @@ /**

>(2, <K, V>(self: MutableHashMap<K, V>, key: K) => {
const hash = Hash.hash(key)
const arr = self.backingMap.get(hash)
if (arr === undefined) {
return self
}
if (Equal.equals(key, arr.k)) {
if (arr.next !== undefined) {
self.backingMap.set(hash, arr.next)
} else {
self.backingMap.delete(hash)
}
self.length = self.length - 1
return self
}
let next: Node<K, V> | undefined = arr.next
let curr = arr
while (next !== undefined) {
if (Equal.equals(key, next.k)) {
curr.next = next.next
self.length = self.length - 1
return self
}
curr = next
next = next.next
}
MutableRef.update(self.backingMap, HashMap.remove(key))
return self

@@ -278,21 +189,3 @@ })

>(3, <K, V>(self: MutableHashMap<K, V>, key: K, value: V) => {
const hash = Hash.hash(key)
const arr = self.backingMap.get(hash)
if (arr === undefined) {
self.backingMap.set(hash, new Node(key, value))
self.length = self.length + 1
return self
}
let c: Node<K, V> | undefined = arr
let l = arr
while (c !== undefined) {
if (Equal.equals(key, c.k)) {
c.v = value
return self
}
l = c
c = c.next
}
self.length = self.length + 1
l.next = new Node(key, value)
MutableRef.update(self.backingMap, HashMap.set(key, value))
return self

@@ -305,2 +198,2 @@ })

*/
export const size = <K, V>(self: MutableHashMap<K, V>): number => self.length
export const size = <K, V>(self: MutableHashMap<K, V>): number => HashMap.size(MutableRef.get(self.backingMap))

@@ -34,6 +34,2 @@ /**

get length() {
return this.keyMap.length
}
[Symbol.iterator](): Iterator<V> {

@@ -40,0 +36,0 @@ return Array.from(this.keyMap).map(([_]) => _)[Symbol.iterator]()

@@ -25,56 +25,2 @@ /**

current: T
/**
* @since 1.0.0
* @category general
*/
get<T>(this: MutableRef<T>): T
/**
* @since 1.0.0
* @category general
*/
set<T>(this: MutableRef<T>, value: T): MutableRef<T>
/**
* @since 1.0.0
* @category general
*/
update<T>(this: MutableRef<T>, f: (value: T) => T): MutableRef<T>
/**
* @since 1.0.0
* @category general
*/
updateAndGet<T>(this: MutableRef<T>, f: (value: T) => T): T
/**
* @since 1.0.0
* @category general
*/
getAndUpdate<T>(this: MutableRef<T>, f: (value: T) => T): T
/**
* @since 1.0.0
* @category general
*/
setAndGet<T>(this: MutableRef<T>, value: T): T
/**
* @since 1.0.0
* @category general
*/
getAndSet<T>(this: MutableRef<T>, value: T): T
/**
* @since 1.0.0
* @category general
*/
compareAndSet<T>(this: MutableRef<T>, oldValue: T, newValue: T): boolean
/**
* @since 1.0.0
* @category general
*/
pipe<T, B>(this: MutableRef<T>, f: (_: MutableRef<T>) => B): B
}

@@ -88,46 +34,2 @@

get<T>(this: MutableRef<T>): T {
return this.current
}
set<T>(this: MutableRef<T>, value: T): MutableRef<T> {
this.current = value
return this
}
setAndGet<T>(this: MutableRef<T>, value: T): T {
this.current = value
return this.current
}
getAndSet<T>(this: MutableRef<T>, value: T): T {
const ret = this.current
this.current = value
return ret
}
compareAndSet<T>(this: MutableRef<T>, oldValue: T, newValue: T): boolean {
if (Equal.equals(oldValue, this.current)) {
this.current = newValue
return true
}
return false
}
pipe<T, B>(this: MutableRef<T>, f: (_: MutableRef<T>) => B): B {
return f(this)
}
update<T>(this: MutableRef<T>, f: (value: T) => T): MutableRef<T> {
return this.set(f(this.get()))
}
updateAndGet<T>(this: MutableRef<T>, f: (value: T) => T): T {
return this.setAndGet(f(this.get()))
}
getAndUpdate<T>(this: MutableRef<T>, f: (value: T) => T): T {
return this.getAndSet(f(this.get()))
}
toString() {

@@ -165,3 +67,9 @@ return `MutableRef(${String(this.current)})`

<T>(self: MutableRef<T>, oldValue: T, newValue: T) => boolean
>(3, (self, oldValue, newValue) => self.compareAndSet(oldValue, newValue))
>(3, (self, oldValue, newValue) => {
if (Equal.equals(oldValue, self.current)) {
self.current = newValue
return true
}
return false
})

@@ -172,3 +80,3 @@ /**

*/
export const decrement = (self: MutableRef<number>): MutableRef<number> => self.update((n) => n - 1)
export const decrement = (self: MutableRef<number>): MutableRef<number> => update(self, (n) => n - 1)

@@ -179,3 +87,3 @@ /**

*/
export const decrementAndGet = (self: MutableRef<number>): number => self.updateAndGet((n) => n - 1)
export const decrementAndGet = (self: MutableRef<number>): number => updateAndGet(self, (n) => n - 1)

@@ -192,3 +100,3 @@ /**

*/
export const getAndDecrement = (self: MutableRef<number>): number => self.getAndUpdate((n) => n - 1)
export const getAndDecrement = (self: MutableRef<number>): number => getAndUpdate(self, (n) => n - 1)

@@ -199,3 +107,3 @@ /**

*/
export const getAndIncrement = (self: MutableRef<number>): number => self.getAndUpdate((n) => n + 1)
export const getAndIncrement = (self: MutableRef<number>): number => getAndUpdate(self, (n) => n + 1)

@@ -212,3 +120,7 @@ /**

<T>(self: MutableRef<T>, value: T) => T
>(2, (self, value) => self.getAndSet(value))
>(2, (self, value) => {
const ret = self.current
self.current = value
return ret
})

@@ -225,3 +137,3 @@ /**

<T>(self: MutableRef<T>, f: (value: T) => T) => T
>(2, (self, f) => self.getAndUpdate(f))
>(2, (self, f) => getAndSet(self, f(get(self))))

@@ -232,3 +144,3 @@ /**

*/
export const increment = (self: MutableRef<number>): MutableRef<number> => self.update((n) => n + 1)
export const increment = (self: MutableRef<number>): MutableRef<number> => update(self, (n) => n + 1)

@@ -239,3 +151,3 @@ /**

*/
export const incrementAndGet = (self: MutableRef<number>): number => self.updateAndGet((n) => n + 1)
export const incrementAndGet = (self: MutableRef<number>): number => updateAndGet(self, (n) => n + 1)

@@ -252,3 +164,6 @@ /**

<T>(self: MutableRef<T>, value: T) => MutableRef<T>
>(2, (self, value) => self.set(value))
>(2, (self, value) => {
self.current = value
return self
})

@@ -265,3 +180,6 @@ /**

<T>(self: MutableRef<T>, value: T) => T
>(2, (self, value) => self.setAndGet(value))
>(2, (self, value) => {
self.current = value
return self.current
})

@@ -278,3 +196,3 @@ /**

<T>(self: MutableRef<T>, f: (value: T) => T) => MutableRef<T>
>(2, (self, f) => self.update(f))
>(2, (self, f) => set(self, f(get(self))))

@@ -291,3 +209,3 @@ /**

<T>(self: MutableRef<T>, f: (value: T) => T) => T
>(2, (self, f) => self.updateAndGet(f))
>(2, (self, f) => setAndGet(self, f(get(self))))

@@ -298,2 +216,2 @@ /**

*/
export const toggle = (self: MutableRef<boolean>): MutableRef<boolean> => self.update((_) => !_)
export const toggle = (self: MutableRef<boolean>): MutableRef<boolean> => update(self, (_) => !_)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc