Skip to content

Commit

Permalink
Merge pull request #83 from ahrjarrett/@ahrjarrett/v0.40.11
Browse files Browse the repository at this point in the history
release v0.40.11
  • Loading branch information
ahrjarrett authored Apr 28, 2024
2 parents 9e4e120 + 692d373 commit 8782b1f
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 138 deletions.
8 changes: 4 additions & 4 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"access": "public",
"baseBranch": "main",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"ignore": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"updateInternalDependencies": "patch"
}
17 changes: 17 additions & 0 deletions .changeset/ninety-cows-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"any-ts": patch
---

## features
adds:
- `object.filter`
- `object.filterKeys`

## deprecations
deprecates:
- `any.arrayof` - use `any.arrayOf` instead
- `any.entriesof` - use `any.entriesOf` instead
- `any.entryof` - use `any.entryOf` instead
- `any.keysof` - use `any.keysOf` instead
- `any.subtypeof` - use `any.subtypeOf` instead
- `any.indexedby` - use `any.indexedBy` instead
2 changes: 1 addition & 1 deletion bin/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const versionTemplate: (version: string) => string
* published.
*/
const writeVersion = (v: string): void => {
return void (v && writeFile(versionFile)(versionTemplate(v)))
return void (v && v.length > 0 && writeFile(versionFile)(versionTemplate(v)))
}

function commitWorktree(version: string): void {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Looking for something that we don't ship yet? [Raise an issue](https://github.co
- [`boolean`](https://github.com/ahrjarrett/any-ts/blob/main/src/boolean/boolean.ts)
- [`char`](https://github.com/ahrjarrett/any-ts/blob/main/src/string/char.ts)
- [`empty`](https://github.com/ahrjarrett/any-ts/blob/main/src/empty.ts)
- [`Kind`](https://github.com/ahrjarrett/any-ts/blob/main/src/kind/kind.ts) (a [higher-kinded type](https://en.wikipedia.org/wiki/Kind_(type_theory)) encoding that is more ergonomic than any other we've found)
- [`Kind`](https://github.com/ahrjarrett/any-ts/blob/main/src/kind/kind.ts), a simple but powerful [HKT](https://en.wikipedia.org/wiki/Kind_(type_theory)) encoding that supports partial application & re-binding
- [`integer`](https://github.com/ahrjarrett/any-ts/blob/main/src/number/integer.ts)
- [`mut`](https://github.com/ahrjarrett/any-ts/blob/main/src/mutable/mutable.ts)
- [`never`](https://github.com/ahrjarrett/any-ts/blob/main/src/semantic-never/semantic-never.ts), a.k.a. semantic never
Expand Down
68 changes: 36 additions & 32 deletions src/any/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ declare namespace any {
/////////////////////
/// 🡓🡓 aliases
export {
arrayof as arrayOf,
dictionary as dict,
indexableby as indexableBy,
indexedby as indexedBy,
keyof as keyOf,
keysof as keysOf,
}
/// 🡑🡑 aliases
///////////////////
Expand Down Expand Up @@ -85,11 +81,13 @@ declare namespace any {
export type single<type extends one = one> = type
export type unary<type extends some.unary = some.unary> = type
export type two<one = _, two = _> = readonly [_1: one, _2: two]
export type pair<left = _, right = _> = readonly [left: left, right: right]
export type double<type extends two = two> = type
export type binary<type extends some.binary = some.binary> = type
export type three<one = _, two = _, three = _> = readonly [_1: one, _2: two, _3: three]
export type triple<type extends three = three> = type
export type ternary<type extends some.ternary = some.ternary> = type
export type record<type extends globalThis.Record<string, _> = globalThis.Record<string, _>> = type

export type predicate<type extends some.predicate = some.predicate> = type
export type asserts<target = _> = never | some.asserts<any, target>
Expand Down Expand Up @@ -129,52 +127,42 @@ declare namespace any {
= keyof invariant
> = type

export type keysof<
export type keysOf<
invariant,
type extends
| any.array<keyof invariant>
= any.array<keyof invariant>
> = type

export type propertyof<
export type propertyOf<
invariant,
type extends
| any.key & keyof invariant
= any.key & keyof invariant
> = type

/**
* @deprecated use {@link propertyof `any.propertyof`} or {@link propertyof `any.propertyOf`} instead
*/
export type showableKeyof<
invariant,
type extends
| any.key & keyof invariant
= any.key & keyof invariant
> = type

export type indexof<
export type indexOf<
invariant extends any.array,
type extends
| Extract<keyof invariant, `${number}`>
= Extract<keyof invariant, `${number}`>
> = type

export type indexedby<
export type indexedBy<
invariant extends any.index,
type extends
| { [ix in invariant]: _ }
= { [ix in invariant]: _ }
> = type

export type indexableby<
export type indexableBy<
invariant extends any.index,
type extends
| { [ix in invariant]: any.index }
= { [ix in invariant]: any.index }
> = type

export type pathof<
export type pathOf<
invariant,
type extends
| pathsof<invariant>
Expand All @@ -188,40 +176,55 @@ declare namespace any {
= { [ix in invariant[0]]: invariant[1] }
> = type

export type arrayof<
export type arrayOf<
invariant,
type extends
| any.array<invariant>
= any.array<invariant>
> = type

export type entryof<
export type entryOf<
invariant,
type extends
| readonly [any.index, invariant]
= readonly [any.index, invariant]
> = type

export type entriesof<
export type entriesOf<
invariant,
type extends
| any.array<readonly [any.index, invariant]>
= any.array<readonly [any.index, invariant]>
> = type

export type fieldof<
export type fieldOf<
invariant,
type extends
| to.entries<invariant>
= to.entries<invariant>
> = type

export type subtypeof<
export type subtypeOf<
invariant,
subtype extends
| invariant extends invariant ? invariant : never
= invariant extends invariant ? invariant : never
> = subtype


export type domainOf<
invariant extends some.function,
target extends
| globalThis.Parameters<invariant>
= globalThis.Parameters<invariant>
> = target

export type codomainOf<
invariant extends some.function,
target extends
| globalThis.ReturnType<invariant>
= globalThis.ReturnType<invariant>
> = target
}

export type any_index = keyof never
Expand All @@ -236,19 +239,20 @@ export type any_array<type = _> = readonly type[]
/** @ts-expect-error */
export interface any_object<type extends object = object> extends id<type> { }
export type any_struct<type = any> = { [ix: string]: type }
export interface any_enumerable<type = unknown> { [ix: number]: type }
export interface any_arraylike<type = unknown> extends any_enumerable<type> { length: number }
export interface any_enumerable<type = _> { [ix: number]: type }
export interface any_arraylike<type = _> extends any_enumerable<type> { length: number }
export interface any_invertible { [ix: any_key]: any_key }
export type any_field<k extends any_index = any_index, v = unknown> = readonly [key: k, value: v]
export type any_entry<type extends readonly [any_index, unknown] = readonly [any_index, unknown]> = type
export type any_field<key extends any_index = any_index, value = _> = readonly [key: key, value: value]
export type any_entry<type extends readonly [any_index, _] = readonly [any_index, _]> = type
export interface any_class<
args extends
| any.array<any>
= any.array<any>
> { new(...arg: args): _ }
= any.array<any>,
target = _
> { new(...arg: args): target }

export type any_json =
| any.scalar
| any_dict<any_json>
| readonly any_json[]
| any_dict<any_json>
;
2 changes: 1 addition & 1 deletion src/err/enforce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ declare namespace enforce {

type uniqNonNumericIndex<type>
= [type] extends [any.entries]
? impl.nonnumericIndex<type> extends any.arrayof<any.index, infer numerics>
? impl.nonnumericIndex<type> extends any.arrayOf<any.index, infer numerics>
? Err2<"NonNumericIndex", numerics>
: enforce.uniqueness.ofEntries<type> extends infer dupes
? unknown extends dupes ? (unknown)
Expand Down
35 changes: 31 additions & 4 deletions src/evaluate/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
eval,
evaluate,
}

Expand All @@ -25,16 +26,42 @@ import type { any } from "../any/exports";
* type bababababab = evaluate<A, -1>
* // ^? type bababababab = { b: { a: { b: { a: { b: { a: { b: { a: { b: { a: { b: any } } } } } } } } } } }
*/
function evaluate<const type>(type: type): evaluate<type, 1>
function evaluate<const type>(type: type): eval<type>
function evaluate<const type, maxDepth extends number>(type: type, maxDepth: maxDepth): evaluate<type, maxDepth>
function evaluate<const type, maxDepth extends number>(type: type, _max?: maxDepth): unknown { return type }

type evaluate<type, maxDepth extends number = 1> = evaluate.go<type, [], maxDepth>
/**
* {@link eval `eval`} is semantically equivalent to {@link evaluate `evaluate`} with
* a hardcoded max-depth of 1.
*
* In practice, you should use `eval` when you want a shallow evaluation, because
* TypeScript can make certain optimizations when it knows that an expression does
* not contain any sub-expressions that require recursion.
*
* @example
* import type { eval } from "any-ts"
*
* interface Abc { abc: Def }
* interface Def { def: Ghi }
* interface Ghi { ghi: Abc }
*
* type Purdy = eval<Abc & Def & Ghi>
* // ^? type Purdy = { abc: 123, def: 456, ghi: 789 }
*/
type eval<type> = never | ({ [k in keyof type]: type[k] })

/**
* {@link evaluate `evaluate`} "evaluates" an expression.
*
* In practice, you should use {@link eval `eval`} when you want a shallow
* evaluation, because TypeScript can make certain optimizations when it
* knows that an expression does not contain any sub-expressions that require recursion.
*/
type evaluate<type, maxDepth extends number = 2> = evaluate.go<type, [], maxDepth>
declare namespace evaluate {
type go<type, currentDepth extends void[], maxDepth extends number>
= maxDepth extends currentDepth["length"] ? type
: type extends any.primitive | any.function ? type
: { [ix in keyof type]
: go<type[ix], [...currentDepth, void], maxDepth> }
: { [ix in keyof type]: go<type[ix], [...currentDepth, void], maxDepth> }
;
}
2 changes: 1 addition & 1 deletion src/evaluate/exports.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { evaluate } from "./evaluate"
export type { eval, evaluate } from "./evaluate"
2 changes: 1 addition & 1 deletion src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export {

export type { any } from "./any/exports"
export type { some } from "./some"
export type { } from "./associative/exports"
export type { object } from "./object/exports"
export type { boolean } from "./boolean/exports"
export type { cache } from "./cache/exports"
export type { evaluate } from "./evaluate/exports"
Expand Down
8 changes: 1 addition & 7 deletions src/kind/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ declare namespace Bind {
interface four<a = _, b = _, c = _, d = _> extends Kind<[a, b, c, d]> { [-1]: Kind<[this[0], this[1], this[2], this[3]]> }
interface five<a = _, b = _, c = _, d = _, e = _> extends Kind<[a, b, c, d, e]> { [-1]: Kind<[this[0], this[1], this[2], this[3], this[4]]> }

type partial<type extends Kind> = globalThis.Omit<type, -1> extends any.subtypeof<type, infer next> ? next : never
type partial<type extends Kind> = globalThis.Omit<type, -1> extends any.subtypeOf<type, infer next> ? next : never
}

type __Bind__ = [
Kind.apply<Bind.two, { 0: "zero" }>,
Kind.apply<Bind.two, { 1: "one" }>,
Kind.apply<Bind.three, { 2: "two" }>,
]

14 changes: 12 additions & 2 deletions src/kind/kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ type kind<params extends nonunion<params> = Scope>

type parseInt<type extends any.index> = `${type & any.key}` extends `${infer x extends number}` ? x : never;
type structured<type> = never | [type] extends [any.array] ? { [ix in Extract<keyof type, `${number}`> as parseInt<ix>]: type[ix] } : type
type satisfies<type> = never | ({ [ix in Exclude<keyof type, -1>]+?: type[ix] })

// type satisfies<type> = never | ({ [ix in Exclude<keyof type, -1>]+?: type[ix] })
type satisfies<fn extends Kind> = never
| ([fn] extends [kind<infer scope>]
? unknown extends scope
? { [ix in globalThis.Exclude<keyof fn, -1>]: fn[ix] }
: scope
: never
)
;


type inferConstraints<fn extends Kind>
= fn extends Kind<infer constraints>
Expand Down Expand Up @@ -155,7 +165,7 @@ type slots<arity extends Arity> = cached.slots[cached.prev[arity]]
type Arity = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
interface Scope { 0?: _, 1?: _, 2?: _, 3?: _, 4?: _, 5?: _, 6?: _, 7?: _, 8?: _, 9?: _ }

type bind<fn extends Kind, args extends satisfies<fn>> = never | (fn & structured<args>)
type bind<fn extends Kind, args extends Partial<satisfies<fn>>> = never | (fn & structured<args>)
type apply<fn extends Kind, args extends satisfies<fn>> = bind<fn, args>[-1]

type constraintsOf<fn extends Kind, type extends satisfies<fn> = satisfies<fn>> = type
Expand Down
4 changes: 2 additions & 2 deletions src/lens/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ declare namespace impl {

type merge<union>
= { [ix in union extends union ? keyof union : never.close.distributive]
: union extends any.indexedby<ix> ? union[ix] : never.close.distributive }
: union extends any.indexedBy<ix> ? union[ix] : never.close.distributive }
;

type mergeTrees<union> = never.as_identity
| [union] extends [any.primitive] ? union :
{ [ix in union extends union ? keyof union : never.close.distributive]
: impl.mergeTrees<union extends any.indexedby<ix> ? union[ix] : never.close.distributive> }
: impl.mergeTrees<union extends any.indexedBy<ix> ? union[ix] : never.close.distributive> }
;

type joinLeft<left, right> = never.as_identity
Expand Down
2 changes: 1 addition & 1 deletion src/lens/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type joinRight<left, right> = never.as_identity
}

type fromPaths<delimiter extends any.showable, type extends any.array<any.string>>
= splitPaths<type, delimiter> extends any.arrayof<any.array<string>, infer split>
= splitPaths<type, delimiter> extends any.arrayOf<any.array<string>, infer split>
? { [ix in keyof split]: traversable.unfold<{}, split[ix]> } extends any.list<infer trees>
? impl.joinTrees<unknown, trees>
: never.close.inline_var<"trees">
Expand Down
8 changes: 0 additions & 8 deletions src/object.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/object/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { object } from "./object"
Loading

0 comments on commit 8782b1f

Please sign in to comment.