Skip to content

Commit a00d3fb

Browse files
authored
Merge pull request #156 from ahrjarrett/changeset-release/main
chore: release package
2 parents 7e8fe28 + 92aaa86 commit a00d3fb

File tree

4 files changed

+93
-86
lines changed

4 files changed

+93
-86
lines changed

.changeset/grumpy-countries-confess.md

Lines changed: 0 additions & 84 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,96 @@
11
# any-ts
22

3+
## 0.46.0
4+
5+
### Minor Changes
6+
7+
- bf5df0f: ### new features
8+
9+
- added `match`, a namespace for advanced pattern matching
10+
- added `any.functions` to describe any array of functions
11+
12+
### breaking changes
13+
14+
a few members of the `some` namespace behave differently than before:
15+
16+
- `some.keyOf`: this change was made to support a homomorphic `object.map` function
17+
that operates on both arrays and objects, preserves structure in either case.
18+
19+
An example implementation:
20+
21+
```typescript
22+
/**
23+
* {@link map `map [overload 1/2]`} ("data-last")
24+
*
25+
* [TypeScript playground](https://tsplay.dev/weA2Yw)
26+
*
27+
* {@link map `map`} takes two arguments:
28+
* 1. a function
29+
* 2. a composite data structure that contains one or more targets to apply the function to
30+
*
31+
* A unique feature of this implementation is its polymorphism: it doesn't care whether the
32+
* composite data structure is an array, or whether it's an object. It will apply the argument
33+
* to each of the children, and will preserve the structure of the original shape.
34+
*
35+
* **Trade-off:** the data-last overload of {@link map `map`} is optimized for function composition.
36+
* It works best when used inside a call to {@link fn.pipe `fn.pipe`} or {@link fn.flow `fn.flow`}.
37+
* It comes with greater potential for code re-use, at the cost of slightly slower performance.
38+
*
39+
* **Ergonomics:** if you'd prefer to provide both arguments at the same time, see overload #2.
40+
*/
41+
export function map<const xs, target>(
42+
fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target
43+
): (xs: xs) => { [ix in keyof xs]: target };
44+
/**
45+
* {@link map `map [overload 2/2]`} ("data-first")
46+
*
47+
* [TypeScript playground](https://tsplay.dev/weA2Yw)
48+
*
49+
* {@link map `map`} is a polymorphic function that accepts a function and a data structure (such
50+
* as an array or object) to apply the function to.
51+
*
52+
* A unique feature of this implementation is its ability to abstract away the type of the data
53+
* structure it maps the function over; whether you pass it an object or an array, it will handle
54+
* applying the function to the data strucuture's values and returning a data structure whose type
55+
* corresponds 1-1 with the type of input.
56+
*
57+
* **Trade-off:** the data-first overload of {@link map `map`} evaluates eagerly. It comes with
58+
* slightly better performance than the data-last overload, at the cost of reusability.
59+
*
60+
* **Ergonomics:** if you'd prefer to use {@link map `map`} in a pipeline, see overload #1.
61+
*/
62+
export function map<const xs, target>(
63+
xs: xs,
64+
fn: (x: xs[some.keyof<xs>], xs: xs) => target
65+
): { [ix in keyof xs]: target };
66+
// impl.
67+
export function map<const xs, target>(
68+
...args:
69+
| [fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target]
70+
| [
71+
xs: xs,
72+
fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target
73+
]
74+
) {
75+
if (args.length === 1) return (xs: xs) => map(xs, args[0]);
76+
else {
77+
const [xs, fn] = args;
78+
if (globalThis.Array.isArray(xs)) return xs.map(fn as never);
79+
else {
80+
let out: any.struct = {};
81+
for (const k in xs) out[k] = fn(xs[k] as never, k as never, xs);
82+
return out;
83+
}
84+
}
85+
}
86+
```
87+
88+
- `some.entryOf`
89+
slightly different semantics to support a polymorphic `object.entries` function
90+
91+
- `some.valueOf`
92+
slightly different semantics to support a polymorphic `object.values` function
93+
394
## 0.45.2
495

596
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "any-ts",
33
"private": false,
4-
"version": "0.45.2",
4+
"version": "0.46.0",
55
"type": "module",
66
"author": {
77
"name": "Andrew Jarrett",

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const ANY_TS_VERSION = "0.45.2" as const
1+
export const ANY_TS_VERSION = "0.46.0" as const
22
export type ANY_TS_VERSION = typeof ANY_TS_VERSION

0 commit comments

Comments
 (0)