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.2 to 0.3.3

31

Function.d.ts

@@ -28,5 +28,17 @@ /**

/**
* Creates a function that can be used in a data-last (aka `pipe`able) or data-first style.
* Creates a function that can be used in a data-last (aka `pipe`able) or
* data-first style.
*
* @param arity - The arity of the uncurried function.
* The first parameter to `dual` is either the arity of the uncurried function
* or a predicate that determines if the function is being used in a data-first
* or data-last style.
*
* Using the arity is the most common use case, but there are some cases where
* you may want to use a predicate. For example, if you have a function that
* takes an optional argument, you can use a predicate to determine if the
* function is being used in a data-first or data-last style.
*
* @param arity - Either the arity of the uncurried function or a predicate
* which determines if the function is being used in a data-first
* or data-last style.
* @param body - The definition of the uncurried function.

@@ -37,2 +49,3 @@ *

*
* // Exampe using arity to determine data-first or data-last style
* export const sum: {

@@ -46,5 +59,17 @@ * (that: number): (self: number) => number

*
* // Example using a predicate to determine data-first or data-last style
* export const sum2: {
* (that: number): (self: number) => number
* (self: number, that: number): number
* } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)
*
* assert.deepStrictEqual(sum(2, 3), 5)
* assert.deepStrictEqual(pipe(2, sum(3)), 5)
*
* @since 1.0.0
*/
export declare const dual: <DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(arity: Parameters<DataFirst>["length"], body: DataFirst) => DataLast & DataFirst;
export declare const dual: {
<DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(arity: Parameters<DataFirst>["length"], body: DataFirst): DataLast & DataFirst;
<DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(isDataFirst: (args: IArguments) => boolean, body: DataFirst): DataLast & DataFirst;
};
/**

@@ -51,0 +76,0 @@ * Apply a function to a given value.

@@ -27,5 +27,17 @@ "use strict";

/**
* Creates a function that can be used in a data-last (aka `pipe`able) or data-first style.
* Creates a function that can be used in a data-last (aka `pipe`able) or
* data-first style.
*
* @param arity - The arity of the uncurried function.
* The first parameter to `dual` is either the arity of the uncurried function
* or a predicate that determines if the function is being used in a data-first
* or data-last style.
*
* Using the arity is the most common use case, but there are some cases where
* you may want to use a predicate. For example, if you have a function that
* takes an optional argument, you can use a predicate to determine if the
* function is being used in a data-first or data-last style.
*
* @param arity - Either the arity of the uncurried function or a predicate
* which determines if the function is being used in a data-first
* or data-last style.
* @param body - The definition of the uncurried function.

@@ -36,2 +48,3 @@ *

*
* // Exampe using arity to determine data-first or data-last style
* export const sum: {

@@ -45,2 +58,11 @@ * (that: number): (self: number) => number

*
* // Example using a predicate to determine data-first or data-last style
* export const sum2: {
* (that: number): (self: number) => number
* (self: number, that: number): number
* } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)
*
* assert.deepStrictEqual(sum(2, 3), 5)
* assert.deepStrictEqual(pipe(2, sum(3)), 5)
*
* @since 1.0.0

@@ -50,5 +72,5 @@ */

const dual = (arity, body) => {
// @ts-expect-error
const isDataFirst = typeof arity === "number" ? args => args.length >= arity : arity;
return function () {
if (arguments.length >= arity) {
if (isDataFirst(arguments)) {
// @ts-expect-error

@@ -55,0 +77,0 @@ return body.apply(this, arguments);

19

HashMap.d.ts

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

import type { HashSet } from "@effect/data/HashSet";
import type { UpdateFn } from "@effect/data/internal/HashMap/node";
import type { Option } from "@effect/data/Option";

@@ -25,2 +24,12 @@ import type { Predicate, Refinement } from "@effect/data/Predicate";

* @since 1.0.0
*/
export declare namespace HashMap {
/**
* @since 1.0.0
* @category models
*/
type UpdateFn<V> = (option: Option<V>) => Option<V>;
}
/**
* @since 1.0.0
* @category refinements

@@ -188,4 +197,4 @@ */

export declare const modifyAt: {
<K, V>(key: K, f: UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>;
<K, V>(self: HashMap<K, V>, key: K, f: UpdateFn<V>): HashMap<K, V>;
<K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>;
<K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>;
};

@@ -206,4 +215,4 @@ /**

export declare const modifyHash: {
<K, V>(key: K, hash: number, f: UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>;
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: UpdateFn<V>): HashMap<K, V>;
<K, V>(key: K, hash: number, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>;
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: HashMap.UpdateFn<V>): HashMap<K, V>;
};

@@ -210,0 +219,0 @@ /**

@@ -819,2 +819,16 @@ /**

*
* @example
* import * as O from "@effect/data/Option"
*
* type Complex = [number, number]
*
* const complex = (real: number, imaginary: number): Complex => [real, imaginary]
*
* assert.deepStrictEqual(O.zipWith(O.none(), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.none(), O.some(1), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.some(2), complex), O.some([1, 2]))
*
* assert.deepStrictEqual(O.zipWith(O.some(1), complex)(O.some(2)), O.some([2, 1]))
*
* @category combining

@@ -944,2 +958,11 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* const evenNumber = (n: number) => n % 2 === 0 ? O.some(n) : O.none()
*
* assert.deepStrictEqual(O.filterMap(O.none(), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(3), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(2), evenNumber), O.some(2))
*
* @category filtering

@@ -964,2 +987,19 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* // predicate
* const isEven = (n: number) => n % 2 === 0
*
* assert.deepStrictEqual(O.filter(O.none(), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(3), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isEven), O.some(2))
*
* // refinement
* const isNumber = (v: unknown): v is number => typeof v === "number"
*
* assert.deepStrictEqual(O.filter(O.none(), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some('hello'), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isNumber), O.some(2))
*
* @category filtering

@@ -966,0 +1006,0 @@ * @since 1.0.0

@@ -882,2 +882,16 @@ "use strict";

*
* @example
* import * as O from "@effect/data/Option"
*
* type Complex = [number, number]
*
* const complex = (real: number, imaginary: number): Complex => [real, imaginary]
*
* assert.deepStrictEqual(O.zipWith(O.none(), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.none(), O.some(1), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.some(2), complex), O.some([1, 2]))
*
* assert.deepStrictEqual(O.zipWith(O.some(1), complex)(O.some(2)), O.some([2, 1]))
*
* @category combining

@@ -1056,2 +1070,11 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* const evenNumber = (n: number) => n % 2 === 0 ? O.some(n) : O.none()
*
* assert.deepStrictEqual(O.filterMap(O.none(), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(3), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(2), evenNumber), O.some(2))
*
* @category filtering

@@ -1078,2 +1101,19 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* // predicate
* const isEven = (n: number) => n % 2 === 0
*
* assert.deepStrictEqual(O.filter(O.none(), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(3), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isEven), O.some(2))
*
* // refinement
* const isNumber = (v: unknown): v is number => typeof v === "number"
*
* assert.deepStrictEqual(O.filter(O.none(), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some('hello'), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isNumber), O.some(2))
*
* @category filtering

@@ -1080,0 +1120,0 @@ * @since 1.0.0

{
"name": "@effect/data",
"version": "0.3.2",
"version": "0.3.3",
"license": "MIT",

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

@@ -31,5 +31,17 @@ /**

/**
* Creates a function that can be used in a data-last (aka `pipe`able) or data-first style.
* Creates a function that can be used in a data-last (aka `pipe`able) or
* data-first style.
*
* @param arity - The arity of the uncurried function.
* The first parameter to `dual` is either the arity of the uncurried function
* or a predicate that determines if the function is being used in a data-first
* or data-last style.
*
* Using the arity is the most common use case, but there are some cases where
* you may want to use a predicate. For example, if you have a function that
* takes an optional argument, you can use a predicate to determine if the
* function is being used in a data-first or data-last style.
*
* @param arity - Either the arity of the uncurried function or a predicate
* which determines if the function is being used in a data-first
* or data-last style.
* @param body - The definition of the uncurried function.

@@ -40,2 +52,3 @@ *

*
* // Exampe using arity to determine data-first or data-last style
* export const sum: {

@@ -49,14 +62,28 @@ * (that: number): (self: number) => number

*
* // Example using a predicate to determine data-first or data-last style
* export const sum2: {
* (that: number): (self: number) => number
* (self: number, that: number): number
* } = dual((args) => args.length === 1, (self: number, that: number): number => self + that)
*
* assert.deepStrictEqual(sum(2, 3), 5)
* assert.deepStrictEqual(pipe(2, sum(3)), 5)
*
* @since 1.0.0
*/
export const dual = <
DataLast extends (...args: Array<any>) => any,
DataFirst extends (...args: Array<any>) => any
>(
arity: Parameters<DataFirst>["length"],
body: DataFirst
): DataLast & DataFirst => {
// @ts-expect-error
export const dual: {
<DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(
arity: Parameters<DataFirst>["length"],
body: DataFirst
): DataLast & DataFirst
<DataLast extends (...args: Array<any>) => any, DataFirst extends (...args: Array<any>) => any>(
isDataFirst: (args: IArguments) => boolean,
body: DataFirst
): DataLast & DataFirst
} = (arity, body) => {
const isDataFirst: (args: IArguments) => boolean = typeof arity === "number" ?
((args) => args.length >= arity) :
arity
return function() {
if (arguments.length >= arity) {
if (isDataFirst(arguments)) {
// @ts-expect-error

@@ -68,3 +95,2 @@ return body.apply(this, arguments)

}
/**

@@ -71,0 +97,0 @@ * Apply a function to a given value.

@@ -9,3 +9,2 @@ /**

import * as _keySet from "@effect/data/internal/HashMap/keySet"
import type { UpdateFn } from "@effect/data/internal/HashMap/node"
import type { Option } from "@effect/data/Option"

@@ -32,2 +31,13 @@ import type { Predicate, Refinement } from "@effect/data/Predicate"

* @since 1.0.0
*/
export declare namespace HashMap {
/**
* @since 1.0.0
* @category models
*/
export type UpdateFn<V> = (option: Option<V>) => Option<V>
}
/**
* @since 1.0.0
* @category refinements

@@ -218,4 +228,4 @@ */

export const modifyAt: {
<K, V>(key: K, f: UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, f: UpdateFn<V>): HashMap<K, V>
<K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>
} = HM.modifyAt

@@ -237,4 +247,4 @@

export const modifyHash: {
<K, V>(key: K, hash: number, f: UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: UpdateFn<V>): HashMap<K, V>
<K, V>(key: K, hash: number, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: HashMap.UpdateFn<V>): HashMap<K, V>
} = HM.modifyHash

@@ -241,0 +251,0 @@

@@ -337,4 +337,4 @@ import * as Equal from "@effect/data/Equal"

export const modifyAt = Dual.dual<
<K, V>(key: K, f: Node.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,
<K, V>(self: HM.HashMap<K, V>, key: K, f: Node.UpdateFn<V>) => HM.HashMap<K, V>
<K, V>(key: K, f: HM.HashMap.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,
<K, V>(self: HM.HashMap<K, V>, key: K, f: HM.HashMap.UpdateFn<V>) => HM.HashMap<K, V>
>(3, (self, key, f) => modifyHash(self, key, Hash.hash(key), f))

@@ -344,5 +344,5 @@

export const modifyHash = Dual.dual<
<K, V>(key: K, hash: number, f: Node.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,
<K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: Node.UpdateFn<V>) => HM.HashMap<K, V>
>(4, <K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: Node.UpdateFn<V>) => {
<K, V>(key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => (self: HM.HashMap<K, V>) => HM.HashMap<K, V>,
<K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => HM.HashMap<K, V>
>(4, <K, V>(self: HM.HashMap<K, V>, key: K, hash: number, f: HM.HashMap.UpdateFn<V>) => {
const size = { value: (self as HashMapImpl<K, V>)._size }

@@ -349,0 +349,0 @@ const newRoot = (self as HashMapImpl<K, V>)._root.modify(

import { equals } from "@effect/data/Equal"
import type { HashMap } from "@effect/data/HashMap"
import { arraySpliceIn, arraySpliceOut, arrayUpdate } from "@effect/data/internal/HashMap/array"

@@ -28,3 +29,3 @@ import { fromBitmap, hashFragment, toBitmap } from "@effect/data/internal/HashMap/bitwise"

_shift: number,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
hash: number,

@@ -59,5 +60,2 @@ key: K,

/** @internal */
export type UpdateFn<V> = (v: O.Option<V>) => O.Option<V>
/** @internal */
export class LeafNode<K, V> {

@@ -76,3 +74,3 @@ readonly _tag = "LeafNode"

shift: number,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
hash: number,

@@ -122,3 +120,3 @@ key: K,

shift: number,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
hash: number,

@@ -161,3 +159,3 @@ key: K,

list: Array<Node<K, V>>,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
key: K,

@@ -201,3 +199,3 @@ size: SizeRef

shift: number,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
hash: number,

@@ -266,3 +264,3 @@ key: K,

shift: number,
f: UpdateFn<V>,
f: HashMap.UpdateFn<V>,
hash: number,

@@ -269,0 +267,0 @@ key: K,

@@ -1040,2 +1040,16 @@ /**

*
* @example
* import * as O from "@effect/data/Option"
*
* type Complex = [number, number]
*
* const complex = (real: number, imaginary: number): Complex => [real, imaginary]
*
* assert.deepStrictEqual(O.zipWith(O.none(), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.none(), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.none(), O.some(1), complex), O.none())
* assert.deepStrictEqual(O.zipWith(O.some(1), O.some(2), complex), O.some([1, 2]))
*
* assert.deepStrictEqual(O.zipWith(O.some(1), complex)(O.some(2)), O.some([2, 1]))
*
* @category combining

@@ -1243,2 +1257,11 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* const evenNumber = (n: number) => n % 2 === 0 ? O.some(n) : O.none()
*
* assert.deepStrictEqual(O.filterMap(O.none(), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(3), evenNumber), O.none())
* assert.deepStrictEqual(O.filterMap(O.some(2), evenNumber), O.some(2))
*
* @category filtering

@@ -1271,2 +1294,19 @@ * @since 1.0.0

*
* @example
* import * as O from "@effect/data/Option"
*
* // predicate
* const isEven = (n: number) => n % 2 === 0
*
* assert.deepStrictEqual(O.filter(O.none(), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(3), isEven), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isEven), O.some(2))
*
* // refinement
* const isNumber = (v: unknown): v is number => typeof v === "number"
*
* assert.deepStrictEqual(O.filter(O.none(), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some('hello'), isNumber), O.none())
* assert.deepStrictEqual(O.filter(O.some(2), isNumber), O.some(2))
*
* @category filtering

@@ -1273,0 +1313,0 @@ * @since 1.0.0

@@ -55,4 +55,13 @@ /**

/**
* Checks if a value is between the lower and upper limit of a bound.
*
* @category predicates
* @since 1.0.0
*/
export const between = <A>(B: Bounded<A>): (a: A) => boolean => order.between(B)(B.minBound, B.maxBound)
/**
* Clamp a value between `minBound` and `maxBound` values.
*
* @category utils
* @since 1.0.0

@@ -65,2 +74,3 @@ */

*
* @category utils
* @since 1.0.0

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

@@ -42,4 +42,12 @@ /**

/**
* Checks if a value is between the lower and upper limit of a bound.
*
* @category predicates
* @since 1.0.0
*/
export declare const between: <A>(B: Bounded<A>) => (a: A) => boolean;
/**
* Clamp a value between `minBound` and `maxBound` values.
*
* @category utils
* @since 1.0.0

@@ -51,2 +59,3 @@ */

*
* @category utils
* @since 1.0.0

@@ -53,0 +62,0 @@ */

@@ -6,3 +6,3 @@ "use strict";

});
exports.reverse = exports.number = exports.min = exports.max = exports.clamp = void 0;
exports.reverse = exports.number = exports.min = exports.max = exports.clamp = exports.between = void 0;
var monoid = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/typeclass/Monoid"));

@@ -39,7 +39,16 @@ var order = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/typeclass/Order"));

/**
* Checks if a value is between the lower and upper limit of a bound.
*
* @category predicates
* @since 1.0.0
*/
exports.number = number;
const between = B => order.between(B)(B.minBound, B.maxBound);
/**
* Clamp a value between `minBound` and `maxBound` values.
*
* @category utils
* @since 1.0.0
*/
exports.number = number;
exports.between = between;
const clamp = B => order.clamp(B)(B.minBound, B.maxBound);

@@ -49,2 +58,3 @@ /**

*
* @category utils
* @since 1.0.0

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

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