Skip to content

Commit

Permalink
feat: fix all slow types
Browse files Browse the repository at this point in the history
  • Loading branch information
baetheus committed Mar 14, 2024
1 parent a4c16af commit fa730f7
Show file tree
Hide file tree
Showing 36 changed files with 450 additions and 309 deletions.
34 changes: 22 additions & 12 deletions array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type { Combinable } from "./combinable.ts";
import type { Comparable } from "./comparable.ts";
import type { Either } from "./either.ts";
import type { Filterable } from "./filterable.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Bind, Flatmappable, Tap } from "./flatmappable.ts";
import type { Initializable } from "./initializable.ts";
import type { Mappable } from "./mappable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Option } from "./option.ts";
import type { Pair } from "./pair.ts";
import type { Foldable } from "./foldable.ts";
Expand Down Expand Up @@ -844,6 +844,15 @@ type Sequence<U extends Kind, R extends AnySub<U>[]> = $<U, [
]
>;

/**
* The return type of sequence for use with type inference.
*
* @since 2.0.0
*/
export type SequenceArray<U extends Kind> = <US extends AnySub<U>[]>(
...uas: US
) => Sequence<U, US>;

/**
* Sequence over an array of type V, inverting the relationship between V and
* ReadonlyArray. This function also keeps the indexed types of in each V at
Expand Down Expand Up @@ -1045,8 +1054,10 @@ export function updateAt(
*
* @since 2.0.0
*/
export function modify<A>(modifyFn: (a: A) => A) {
return (index: number) => (arr: ReadonlyArray<A>): ReadonlyArray<A> =>
export function modify<A>(
modifyFn: (a: A) => A,
): (index: number) => (ua: ReadonlyArray<A>) => ReadonlyArray<A> {
return (index) => (arr) =>
isOutOfBounds(index, arr)
? arr
: _unsafeUpdateAt(index, modifyFn(arr[index]), arr);
Expand Down Expand Up @@ -1122,9 +1133,10 @@ export function lookup(index: number): <A>(arr: ReadonlyArray<A>) => Option<A> {
*
* @since 2.0.0
*/
export function deleteAt(index: number) {
return <A>(arr: ReadonlyArray<A>): ReadonlyArray<A> =>
isOutOfBounds(index, arr) ? arr : _unsafeDeleteAt(index, arr);
export function deleteAt(
index: number,
): <A>(ua: ReadonlyArray<A>) => ReadonlyArray<A> {
return (arr) => isOutOfBounds(index, arr) ? arr : _unsafeDeleteAt(index, arr);
}

/**
Expand Down Expand Up @@ -1515,16 +1527,14 @@ export const WrappableArray: Wrappable<KindArray> = { wrap };
/**
* @since 2.0.0
*/
export const tap: <A>(
fa: (value: A) => void,
) => (ua: ReadonlyArray<A>) => ReadonlyArray<A> = createTap(FlatmappableArray);
export const tap: Tap<KindArray> = createTap(FlatmappableArray);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableArray);
export const bind: Bind<KindArray> = createBind(FlatmappableArray);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(MappableArray);
export const bindTo: BindTo<KindArray> = createBindTo(MappableArray);
10 changes: 5 additions & 5 deletions async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { Kind, Out } from "./kind.ts";
import type { Applicable } from "./applicable.ts";
import type { Combinable } from "./combinable.ts";
import type { Initializable } from "./initializable.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Mappable } from "./mappable.ts";
import type { Bind, Flatmappable, Tap } from "./flatmappable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Sync } from "./sync.ts";
import type { Wrappable } from "./wrappable.ts";

Expand Down Expand Up @@ -167,14 +167,14 @@ export const FlatmappableAsyncSeq: Flatmappable<KindAsync> = {
/**
* @since 2.0.0
*/
export const tap = createTap(FlatmappableAsync);
export const tap: Tap<KindAsync> = createTap(FlatmappableAsync);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableAsync);
export const bind: Bind<KindAsync> = createBind(FlatmappableAsync);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(MappableAsync);
export const bindTo: BindTo<KindAsync> = createBindTo(MappableAsync);
16 changes: 10 additions & 6 deletions async_either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import type { Async } from "./async.ts";
import type { Bimappable } from "./bimappable.ts";
import type { Combinable } from "./combinable.ts";
import type { Either } from "./either.ts";
import type { Failable } from "./failable.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Failable, Tap } from "./failable.ts";
import type { Bind, Flatmappable } from "./flatmappable.ts";
import type { Initializable } from "./initializable.ts";
import type { Mappable } from "./mappable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Wrappable } from "./wrappable.ts";

import * as E from "./either.ts";
Expand Down Expand Up @@ -483,14 +483,18 @@ export const WrappableAsyncEither: Wrappable<KindAsyncEither> = {
/**
* @since 2.0.0
*/
export const tap = createTap(FailableAsyncEitherParallel);
export const tap: Tap<KindAsyncEither> = createTap(FailableAsyncEitherParallel);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableAsyncEitherParallel);
export const bind: Bind<KindAsyncEither> = createBind(
FlatmappableAsyncEitherParallel,
);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(FlatmappableAsyncEitherParallel);
export const bindTo: BindTo<KindAsyncEither> = createBindTo(
FlatmappableAsyncEitherParallel,
);
18 changes: 11 additions & 7 deletions async_iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import type { Kind, Out } from "./kind.ts";
import type { Applicable } from "./applicable.ts";
import type { Wrappable } from "./wrappable.ts";
import type { Either } from "./either.ts";
import type { Filterable } from "./filterable.ts";
import type { Mappable } from "./mappable.ts";
import type { Bind, Flatmappable, Tap } from "./flatmappable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Option } from "./option.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Either } from "./either.ts";
import type { Pair } from "./pair.ts";
import type { Predicate } from "./predicate.ts";
import type { Refinement } from "./refinement.ts";
import type { Wrappable } from "./wrappable.ts";

import { createBind, createTap } from "./flatmappable.ts";
import { createBindTo } from "./mappable.ts";
Expand Down Expand Up @@ -429,14 +429,18 @@ export const WrappableAsyncIterable: Wrappable<KindAsyncIterable> = { wrap };
/**
* @since 2.0.0
*/
export const tap = createTap(FlatmappableAsyncIterable);
export const tap: Tap<KindAsyncIterable> = createTap(FlatmappableAsyncIterable);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableAsyncIterable);
export const bind: Bind<KindAsyncIterable> = createBind(
FlatmappableAsyncIterable,
);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(MappableAsyncIterable);
export const bindTo: BindTo<KindAsyncIterable> = createBindTo(
MappableAsyncIterable,
);
6 changes: 4 additions & 2 deletions combinable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ export function min<A>(sortable: Sortable<A>): Combinable<A> {
*
* @since 2.0.0
*/
export function intercalcate<A>(middle: A) {
return ({ combine }: Combinable<A>): Combinable<A> =>
export function intercalcate<A>(
middle: A,
): (C: Combinable<A>) => Combinable<A> {
return ({ combine }) =>
fromCombine((second) => (first) => combine(second)(combine(middle)(first)));
}

Expand Down
10 changes: 5 additions & 5 deletions contrib/free.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export function isLink<A>(ua: Free<A>): ua is Link<A> {
export function match<A, O>(
onNode: (value: A) => O,
onLink: (first: Free<A>, second: Free<A>) => O,
) {
return (ta: Free<A>): O => {
switch (ta.tag) {
): (ua: Free<A>) => O {
return (ua) => {
switch (ua.tag) {
case "Node":
return onNode(ta.value);
return onNode(ua.value);
case "Link":
return onLink(ta.first, ta.second);
return onLink(ua.first, ua.second);
}
};
}
Expand Down
21 changes: 0 additions & 21 deletions contrib/generator.ts

This file was deleted.

14 changes: 7 additions & 7 deletions contrib/most.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Scheduler, Stream } from "npm:@most/types@1.1.0";
import type { $, Kind, Nest, Out } from "../kind.ts";
import type { Wrappable } from "../wrappable.ts";
import type { Mappable } from "../mappable.ts";
import type { Applicable } from "../applicable.ts";
import type { Flatmappable } from "../flatmappable.ts";
import type { Bind, Flatmappable, Tap } from "../flatmappable.ts";
import type { BindTo, Mappable } from "../mappable.ts";
import type { Scheduler, Stream } from "npm:@most/types@1.1.0";
import type { Wrappable } from "../wrappable.ts";

import * as M from "npm:@most/core@1.6.1";
import { createBind, createTap } from "../flatmappable.ts";
Expand Down Expand Up @@ -96,11 +96,11 @@ export const FlatmappableStream: Flatmappable<KindStream> = {
flatmap,
};

export const bind = createBind(FlatmappableStream);
export const bind: Bind<KindStream> = createBind(FlatmappableStream);

export const bindTo = createBindTo(FlatmappableStream);
export const bindTo: BindTo<KindStream> = createBindTo(FlatmappableStream);

export const tap = createTap(FlatmappableStream);
export const tap: Tap<KindStream> = createTap(FlatmappableStream);

export interface TransformStream<U extends Kind> extends Kind {
readonly kind: Stream<Nest<U, this>>;
Expand Down
28 changes: 14 additions & 14 deletions datum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import type { $, Kind, Out } from "./kind.ts";
import type { Applicable } from "./applicable.ts";
import type { Combinable } from "./combinable.ts";
import type { Filterable } from "./filterable.ts";
import type { Mappable } from "./mappable.ts";
import type { Wrappable } from "./wrappable.ts";
import type { Comparable } from "./comparable.ts";
import type { Either } from "./either.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Filterable } from "./filterable.ts";
import type { Bind, Flatmappable, Tap } from "./flatmappable.ts";
import type { Initializable } from "./initializable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Option } from "./option.ts";
import type { Pair } from "./pair.ts";
import type { Predicate } from "./predicate.ts";
import type { Refinement } from "./refinement.ts";
import type { Showable } from "./showable.ts";
import type { Sortable } from "./sortable.ts";
import type { Traversable } from "./traversable.ts";
import type { Wrappable } from "./wrappable.ts";

import * as O from "./option.ts";
import { createBind, createTap } from "./flatmappable.ts";
Expand Down Expand Up @@ -218,26 +218,26 @@ export function match<A, B>(
onPending: () => B,
onReplete: (a: A) => B,
onRefresh: (a: A) => B,
) {
return (ma: Datum<A>): B => {
switch (ma.tag) {
): (ua: Datum<A>) => B {
return (ua) => {
switch (ua.tag) {
case "Initial":
return onInitial();
case "Pending":
return onPending();
case "Refresh":
return onRefresh(ma.value);
return onRefresh(ua.value);
case "Replete":
return onReplete(ma.value);
return onReplete(ua.value);
}
};
}

/**
* @since 2.0.0
*/
export function getOrElse<A>(onNone: () => A) {
return match<A, A>(onNone, onNone, identity, identity);
export function getOrElse<A>(onNone: () => A): (ua: Datum<A>) => A {
return match(onNone, onNone, identity, identity);
}

/**
Expand Down Expand Up @@ -565,14 +565,14 @@ export const FilterableDatum: Filterable<KindDatum> = {
/**
* @since 2.0.0
*/
export const tap = createTap(FlatmappableDatum);
export const tap: Tap<KindDatum> = createTap(FlatmappableDatum);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableDatum);
export const bind: Bind<KindDatum> = createBind(FlatmappableDatum);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(MappableDatum);
export const bindTo: BindTo<KindDatum> = createBindTo(MappableDatum);
14 changes: 7 additions & 7 deletions decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import type { Applicable } from "./applicable.ts";
import type { Combinable } from "./combinable.ts";
import type { Composable } from "./composable.ts";
import type { Either } from "./either.ts";
import type { Flatmappable } from "./flatmappable.ts";
import type { Bind, Flatmappable, Tap } from "./flatmappable.ts";
import type { FnEither } from "./fn_either.ts";
import type { Forest } from "./tree.ts";
import type { Literal, Schemable } from "./schemable.ts";
import type { Mappable } from "./mappable.ts";
import type { BindTo, Mappable } from "./mappable.ts";
import type { Predicate } from "./predicate.ts";
import type { Premappable } from "./premappable.ts";
import type { ReadonlyRecord } from "./record.ts";
Expand Down Expand Up @@ -1469,7 +1469,7 @@ export function union<B, I>(
*
* @since 2.0.0
*/
export const _null = literal(null);
export const _null: Decoder<unknown, null> = literal(null);

/**
* A decoder combinator that modifies an existing decoder to accept null as an
Expand Down Expand Up @@ -1499,7 +1499,7 @@ export function nullable<D, A>(
*
* @since 2.0.0
*/
export const _undefined = literal(undefined);
export const _undefined: Decoder<unknown, undefined> = literal(undefined);

/**
* A decoder combinator that modifies an existing decoder to accept undefined
Expand Down Expand Up @@ -1915,14 +1915,14 @@ export const WrappableDecoder: Wrappable<KindDecoder> = { wrap };
/**
* @since 2.0.0
*/
export const tap = createTap(FlatmappableDecoder);
export const tap: Tap<KindDecoder> = createTap(FlatmappableDecoder);

/**
* @since 2.0.0
*/
export const bind = createBind(FlatmappableDecoder);
export const bind: Bind<KindDecoder> = createBind(FlatmappableDecoder);

/**
* @since 2.0.0
*/
export const bindTo = createBindTo(MappableDecoder);
export const bindTo: BindTo<KindDecoder> = createBindTo(MappableDecoder);
Loading

0 comments on commit fa730f7

Please sign in to comment.