From 92aaa86afe7ad1337460da57c22ceacc9c616554 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 22 Jun 2024 19:36:22 +0000 Subject: [PATCH] bump: v0.46.0 --- .changeset/grumpy-countries-confess.md | 84 ------------------------ CHANGELOG.md | 91 ++++++++++++++++++++++++++ package.json | 2 +- src/version.ts | 2 +- 4 files changed, 93 insertions(+), 86 deletions(-) delete mode 100644 .changeset/grumpy-countries-confess.md diff --git a/.changeset/grumpy-countries-confess.md b/.changeset/grumpy-countries-confess.md deleted file mode 100644 index 958fbd6..0000000 --- a/.changeset/grumpy-countries-confess.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -"any-ts": minor ---- - -### new features -- added `match`, a namespace for advanced pattern matching -- added `any.functions` to describe any array of functions - -### breaking changes - -a few members of the `some` namespace behave differently than before: - -- `some.keyOf`: this change was made to support a homomorphic `object.map` function - that operates on both arrays and objects, preserves structure in either case. - - An example implementation: - - ```typescript - /** - * {@link map `map [overload 1/2]`} ("data-last") - * - * [TypeScript playground](https://tsplay.dev/weA2Yw) - * - * {@link map `map`} takes two arguments: - * 1. a function - * 2. a composite data structure that contains one or more targets to apply the function to - * - * A unique feature of this implementation is its polymorphism: it doesn't care whether the - * composite data structure is an array, or whether it's an object. It will apply the argument - * to each of the children, and will preserve the structure of the original shape. - * - * **Trade-off:** the data-last overload of {@link map `map`} is optimized for function composition. - * It works best when used inside a call to {@link fn.pipe `fn.pipe`} or {@link fn.flow `fn.flow`}. - * It comes with greater potential for code re-use, at the cost of slightly slower performance. - * - * **Ergonomics:** if you'd prefer to provide both arguments at the same time, see overload #2. - */ - export function map - (fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target): (xs: xs) => { [ix in keyof xs]: target } - /** - * {@link map `map [overload 2/2]`} ("data-first") - * - * [TypeScript playground](https://tsplay.dev/weA2Yw) - * - * {@link map `map`} is a polymorphic function that accepts a function and a data structure (such - * as an array or object) to apply the function to. - * - * A unique feature of this implementation is its ability to abstract away the type of the data - * structure it maps the function over; whether you pass it an object or an array, it will handle - * applying the function to the data strucuture's values and returning a data structure whose type - * corresponds 1-1 with the type of input. - * - * **Trade-off:** the data-first overload of {@link map `map`} evaluates eagerly. It comes with - * slightly better performance than the data-last overload, at the cost of reusability. - * - * **Ergonomics:** if you'd prefer to use {@link map `map`} in a pipeline, see overload #1. - */ - export function map - (xs: xs, fn: (x: xs[some.keyof], xs: xs) => target): { [ix in keyof xs]: target } - // impl. - export function map( - ...args: - | [fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target] - | [xs: xs, fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target] - ) { - if(args.length === 1) return (xs: xs) => map(xs, args[0]) - else { - const [xs, fn] = args - if(globalThis.Array.isArray(xs)) return xs.map(fn as never) - else { - let out: any.struct = {} - for(const k in xs) - out[k] = fn(xs[k] as never, k as never, xs) - return out - } - } - } - ``` - -- `some.entryOf` - slightly different semantics to support a polymorphic `object.entries` function - -- `some.valueOf` - slightly different semantics to support a polymorphic `object.values` function diff --git a/CHANGELOG.md b/CHANGELOG.md index dd16136..617ac48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,96 @@ # any-ts +## 0.46.0 + +### Minor Changes + +- bf5df0f: ### new features + + - added `match`, a namespace for advanced pattern matching + - added `any.functions` to describe any array of functions + + ### breaking changes + + a few members of the `some` namespace behave differently than before: + + - `some.keyOf`: this change was made to support a homomorphic `object.map` function + that operates on both arrays and objects, preserves structure in either case. + + An example implementation: + + ```typescript + /** + * {@link map `map [overload 1/2]`} ("data-last") + * + * [TypeScript playground](https://tsplay.dev/weA2Yw) + * + * {@link map `map`} takes two arguments: + * 1. a function + * 2. a composite data structure that contains one or more targets to apply the function to + * + * A unique feature of this implementation is its polymorphism: it doesn't care whether the + * composite data structure is an array, or whether it's an object. It will apply the argument + * to each of the children, and will preserve the structure of the original shape. + * + * **Trade-off:** the data-last overload of {@link map `map`} is optimized for function composition. + * It works best when used inside a call to {@link fn.pipe `fn.pipe`} or {@link fn.flow `fn.flow`}. + * It comes with greater potential for code re-use, at the cost of slightly slower performance. + * + * **Ergonomics:** if you'd prefer to provide both arguments at the same time, see overload #2. + */ + export function map( + fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target + ): (xs: xs) => { [ix in keyof xs]: target }; + /** + * {@link map `map [overload 2/2]`} ("data-first") + * + * [TypeScript playground](https://tsplay.dev/weA2Yw) + * + * {@link map `map`} is a polymorphic function that accepts a function and a data structure (such + * as an array or object) to apply the function to. + * + * A unique feature of this implementation is its ability to abstract away the type of the data + * structure it maps the function over; whether you pass it an object or an array, it will handle + * applying the function to the data strucuture's values and returning a data structure whose type + * corresponds 1-1 with the type of input. + * + * **Trade-off:** the data-first overload of {@link map `map`} evaluates eagerly. It comes with + * slightly better performance than the data-last overload, at the cost of reusability. + * + * **Ergonomics:** if you'd prefer to use {@link map `map`} in a pipeline, see overload #1. + */ + export function map( + xs: xs, + fn: (x: xs[some.keyof], xs: xs) => target + ): { [ix in keyof xs]: target }; + // impl. + export function map( + ...args: + | [fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target] + | [ + xs: xs, + fn: (x: xs[some.keyof], ix: some.keyof, xs: xs) => target + ] + ) { + if (args.length === 1) return (xs: xs) => map(xs, args[0]); + else { + const [xs, fn] = args; + if (globalThis.Array.isArray(xs)) return xs.map(fn as never); + else { + let out: any.struct = {}; + for (const k in xs) out[k] = fn(xs[k] as never, k as never, xs); + return out; + } + } + } + ``` + + - `some.entryOf` + slightly different semantics to support a polymorphic `object.entries` function + + - `some.valueOf` + slightly different semantics to support a polymorphic `object.values` function + ## 0.45.2 ### Patch Changes diff --git a/package.json b/package.json index 020d196..c45d734 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "any-ts", "private": false, - "version": "0.45.2", + "version": "0.46.0", "type": "module", "author": { "name": "Andrew Jarrett", diff --git a/src/version.ts b/src/version.ts index 7f9aa2b..079b902 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ -export const ANY_TS_VERSION = "0.45.2" as const +export const ANY_TS_VERSION = "0.46.0" as const export type ANY_TS_VERSION = typeof ANY_TS_VERSION \ No newline at end of file