Skip to content

Commit

Permalink
Merge branch 'record_omit_immutable_props' into record_map
Browse files Browse the repository at this point in the history
  • Loading branch information
baoshan committed Jul 18, 2022
2 parents d91aaef + 687c665 commit 931c1d5
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 112 deletions.
8 changes: 4 additions & 4 deletions affect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export function fromIOEither<A, B, C = never>(
*/
export function fromOption<B, C>(
onNone: (c: C) => B,
): (<A>(ta: Option<A>) => Affect<C, B, A>) {
): <A>(ta: Option<A>) => Affect<C, B, A> {
return <A>(ta: Option<A>) =>
(c) =>
isNone(ta)
Expand Down Expand Up @@ -491,13 +491,13 @@ export function left<A = never, B = never, C = never>(
*/
export function map<A, I>(
fai: (a: A) => I,
): (<R, E>(ta: Affect<R, E, A>) => Affect<R, E, I>) {
): <R, E>(ta: Affect<R, E, A>) => Affect<R, E, I> {
return (ta) => flow(ta, then(eitherMap(fai)));
}

export function mapLeft<B, J>(
fbj: (b: B) => J,
): (<R, A>(ta: Affect<R, B, A>) => Affect<R, J, A>) {
): <R, A>(ta: Affect<R, B, A>) => Affect<R, J, A> {
return (ta) => flow(ta, then(eitherMapLeft(fbj)));
}

Expand All @@ -507,7 +507,7 @@ export function of<A, B = never, C = never>(a: A): Affect<C, B, A> {

export function recover<E, A>(
fea: (e: E) => A,
): (<R>(ta: Affect<R, E, A>) => Affect<R, E, A>) {
): <R>(ta: Affect<R, E, A>) => Affect<R, E, A> {
return (ta) =>
flow(ta, then(eitherFold(flow(fea, eitherRight), eitherRight)));
}
Expand Down
26 changes: 13 additions & 13 deletions array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function unsafeDeleteAt<A>(

export function unsafeAppend<A>(
last: A,
): ((ta: Array<A>) => Array<A>) {
): (ta: Array<A>) => Array<A> {
return (ta) => {
ta.push(last);
return ta;
Expand All @@ -77,7 +77,7 @@ export function unsafeAppend<A>(

export function unsafePrepend<A>(
head: A,
): ((ta: Array<A>) => Array<A>) {
): (ta: Array<A>) => Array<A> {
return (ta) => {
ta.unshift(head);
return ta;
Expand All @@ -90,13 +90,13 @@ export function isEmpty<A>(ta: ReadonlyArray<A>): boolean {

export function alt<A>(
tb: ReadonlyArray<A>,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<A>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<A> {
return (ta) => ta.length === 0 ? tb : ta;
}

export function map<A, I>(
fai: (a: A, i: number) => I,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<I>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<I> {
return (ta) => {
let index = -1;
const length = ta.length;
Expand All @@ -113,7 +113,7 @@ export function map<A, I>(
export function reduce<A, O>(
foao: (o: O, a: A, i: number) => O,
o: O,
): ((ta: ReadonlyArray<A>) => O) {
): (ta: ReadonlyArray<A>) => O {
return (ta) => {
let result = o;
let index = -1;
Expand All @@ -129,7 +129,7 @@ export function reduce<A, O>(

export function concat<A>(
right: ReadonlyArray<A>,
): ((left: ReadonlyArray<A>) => ReadonlyArray<A>) {
): (left: ReadonlyArray<A>) => ReadonlyArray<A> {
if (right.length === 0) {
return identity;
}
Expand Down Expand Up @@ -175,19 +175,19 @@ export function join<A>(

export function chain<A, I>(
fati: (a: A) => ReadonlyArray<I>,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<I>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<I> {
return flow(map(fati), join);
}

export function ap<A, I>(
tfai: ReadonlyArray<(a: A) => I>,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<I>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<I> {
return (ta) => pipe(tfai, chain(flow(map, apply(ta))));
}

export function filter<A>(
predicate: Predicate<A>,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<A>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<A> {
return (ta) => {
let index = -1;
let resultIndex = 0;
Expand Down Expand Up @@ -223,13 +223,13 @@ export function traverse<VRI extends URIS>(

export function append<A>(
last: A,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<A>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<A> {
return (ma) => [...ma, last];
}

export function prepend<A>(
head: A,
): ((ta: ReadonlyArray<A>) => ReadonlyArray<A>) {
): (ta: ReadonlyArray<A>) => ReadonlyArray<A> {
return (ma) => [head, ...ma];
}

Expand Down Expand Up @@ -438,9 +438,9 @@ export function getMonoid<A = never>(): T.Monoid<ReadonlyArray<A>> {

export const createSequence = <VRI extends URIS>(
A: T.Applicative<VRI>,
): (<A, B, C, D>(
): <A, B, C, D>(
ta: Kind<VRI, [A, B, C, D]>[],
) => Kind<VRI, [ReadonlyArray<A>, B, C, D]>) => {
) => Kind<VRI, [ReadonlyArray<A>, B, C, D]> => {
// deno-lint-ignore no-explicit-any
return pipe(A.map(identity), traverse(A)) as any;
};
Expand Down
2 changes: 1 addition & 1 deletion async_iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function ap<A, I>(
}

export function map<A, I>(
fai: (a: A) => (I | PromiseLike<I>),
fai: (a: A) => I | PromiseLike<I>,
): (ta: AsyncIterable<A>) => AsyncIterable<I> {
return (ta) =>
make(async function* () {
Expand Down
8 changes: 4 additions & 4 deletions const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ export function make<E, A = never>(e: E): Const<E, A> {

export function map<A, I>(
_fai: (a: A) => I,
): (<B = never>(ta: Const<B, A>) => Const<B, I>) {
): <B = never>(ta: Const<B, A>) => Const<B, I> {
return identity;
}

export function contramap<A, I>(
_fai: (a: A) => I,
): (<B = never>(ta: Const<B, I>) => Const<B, A>) {
): <B = never>(ta: Const<B, I>) => Const<B, A> {
return identity;
}

export function bimap<A, B, I, J>(
fbj: (b: B) => J,
_fai: (a: A) => I,
): ((tab: Const<B, A>) => Const<J, I>) {
): (tab: Const<B, A>) => Const<J, I> {
return (tab) => make(fbj(tab));
}

export function mapLeft<B, J>(
fbj: (b: B) => J,
): (<A = never>(tab: Const<B, A>) => Const<J, A>) {
): <A = never>(tab: Const<B, A>) => Const<J, A> {
return bimap(fbj, identity);
}

Expand Down
6 changes: 3 additions & 3 deletions datum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function of<A>(a: A): Datum<A> {
return replete(a);
}

export function map<A, I>(fai: (a: A) => I): ((ta: Datum<A>) => Datum<I>) {
export function map<A, I>(fai: (a: A) => I): (ta: Datum<A>) => Datum<I> {
return fold(
constInitial,
constPending,
Expand All @@ -153,7 +153,7 @@ export function map<A, I>(fai: (a: A) => I): ((ta: Datum<A>) => Datum<I>) {

export function chain<A, I>(
fati: (a: A) => Datum<I>,
): ((ta: Datum<A>) => Datum<I>) {
): (ta: Datum<A>) => Datum<I> {
return fold(
constInitial,
constPending,
Expand All @@ -172,7 +172,7 @@ export function join<A>(taa: Datum<Datum<A>>): Datum<A> {
return pipe(taa, chain(identity));
}

export function alt<A>(tb: Datum<A>): ((ta: Datum<A>) => Datum<A>) {
export function alt<A>(tb: Datum<A>): (ta: Datum<A>) => Datum<A> {
return (ta) => isSome(ta) ? ta : tb;
}

Expand Down
16 changes: 7 additions & 9 deletions derivations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,20 @@ export function createDo<URI extends URIS>(
Do: <B = never, C = never, D = never>() => M.of<{}, B, C, D>({}),
bindTo: <N extends string>(
name: N,
): (<A, B, C, D>(
): <A, B, C, D>(
ta: Kind<URI, [A, B, C, D]>,
) => Kind<URI, [{ [K in N]: A }, B, C, D]>) =>
) => Kind<URI, [{ [K in N]: A }, B, C, D]> =>
// deno-lint-ignore no-explicit-any
M.map((a: any): any => ({ [name]: a })),
bind: <N extends string, A, I, B, C, D>(
name: Exclude<N, keyof A>,
fati: (a: A) => Kind<URI, [I, B, C, D]>,
): (
(
ma: Kind<URI, [A, B, C, D]>,
) => Kind<
URI,
[{ readonly [K in keyof A | N]: K extends keyof A ? A[K] : I }, B, C, D]
>
) =>
ma: Kind<URI, [A, B, C, D]>,
) => Kind<
URI,
[{ readonly [K in keyof A | N]: K extends keyof A ? A[K] : I }, B, C, D]
> =>
// deno-lint-ignore no-explicit-any
M.chain((a: any): any =>
// deno-lint-ignore no-explicit-any
Expand Down
22 changes: 11 additions & 11 deletions either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function getRightMonad<E>(
export function bimap<A, B, I, J>(
fbj: (b: B) => J,
fai: (a: A) => I,
): ((ta: Either<B, A>) => Either<J, I>) {
): (ta: Either<B, A>) => Either<J, I> {
return (ta) => isLeft(ta) ? left(fbj(ta.left)) : right(fai(ta.right));
}

Expand All @@ -230,13 +230,13 @@ export function stringifyJSON<E>(
return tryCatch(() => JSON.stringify(u), onError);
}

export function widen<F>(): (<E, A>(ta: Either<E, A>) => Either<E | F, A>) {
export function widen<F>(): <E, A>(ta: Either<E, A>) => Either<E | F, A> {
return identity;
}

export function map<A, I>(
fai: (a: A) => I,
): (<B>(ta: Either<B, A>) => Either<B, I>) {
): <B>(ta: Either<B, A>) => Either<B, I> {
return (ta) => isLeft(ta) ? ta : right(fai(ta.right));
}

Expand All @@ -246,14 +246,14 @@ export function chainLeft<E, A, J>(fej: (e: E) => Either<J, A>) {

export function ap<A, I, B>(
tfai: Either<B, (a: A) => I>,
): ((ta: Either<B, A>) => Either<B, I>) {
): (ta: Either<B, A>) => Either<B, I> {
return (ta) =>
isLeft(ta) ? ta : isLeft(tfai) ? tfai : right(tfai.right(ta.right));
}

export function chain<A, I, B>(
fati: (a: A) => Either<B, I>,
): ((ta: Either<B, A>) => Either<B, I>) {
): (ta: Either<B, A>) => Either<B, I> {
return (ta) => isLeft(ta) ? ta : fati(ta.right);
}

Expand All @@ -263,34 +263,34 @@ export function join<A, B>(ta: Either<B, Either<B, A>>): Either<B, A> {

export function mapLeft<B, J>(
fbj: (b: B) => J,
): (<A>(ta: Either<B, A>) => Either<J, A>) {
): <A>(ta: Either<B, A>) => Either<J, A> {
return (ta) => isLeft(ta) ? left(fbj(ta.left)) : ta;
}

export function alt<A, B>(
tb: Either<B, A>,
): ((ta: Either<B, A>) => Either<B, A>) {
): (ta: Either<B, A>) => Either<B, A> {
return (ta) => isLeft(ta) ? tb : ta;
}

export function extend<A, I, B>(
ftai: (ta: Either<B, A>) => I,
): ((ta: Either<B, A>) => Either<B, I>) {
): (ta: Either<B, A>) => Either<B, I> {
return (ta) => right(ftai(ta));
}

export function reduce<A, O>(
foao: (o: O, a: A) => O,
o: O,
): (<B>(ta: Either<B, A>) => O) {
): <B>(ta: Either<B, A>) => O {
return (ta) => isLeft(ta) ? o : foao(o, ta.right);
}

export function traverse<VRI extends URIS>(
A: T.Applicative<VRI>,
): (<A, I, J, K, L>(
): <A, I, J, K, L>(
faui: (a: A) => Kind<VRI, [I, J, K, L]>,
) => <B>(ta: Either<B, A>) => Kind<VRI, [Either<B, I>, J, K, L]>) {
) => <B>(ta: Either<B, A>) => Kind<VRI, [Either<B, I>, J, K, L]> {
return (faui) =>
fold((l) => A.of(left(l)), flow(faui, A.map((r) => right(r))));
}
Expand Down
4 changes: 2 additions & 2 deletions fns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function compose<B, C>(
*/
export function swap<A, B, C>(
fabc: (a: A) => (b: B) => C,
): ((b: B) => (a: A) => C) {
): (b: B) => (a: A) => C {
return (b: B) => (a: A): C => fabc(a)(b);
}

Expand Down Expand Up @@ -242,7 +242,7 @@ export function reject<A = never, B = unknown>(b: B): Promise<A> {
* A curried alias of Promise.then
*/
export function then<A, B>(
fab: (a: A) => (B | Promise<B>),
fab: (a: A) => B | Promise<B>,
): (ta: Promise<A>) => Promise<B> {
return (ta: Promise<A>): Promise<B> => ta.then(fab);
}
Expand Down
6 changes: 3 additions & 3 deletions identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export function of<A>(a: A): Identity<A> {

export function map<A, I>(
fai: (a: A) => I,
): ((ta: Identity<A>) => Identity<I>) {
): (ta: Identity<A>) => Identity<I> {
return fai;
}

export function ap<A, I>(
tfai: Identity<(a: A) => I>,
): ((ta: Identity<A>) => Identity<I>) {
): (ta: Identity<A>) => Identity<I> {
return tfai;
}

Expand All @@ -36,7 +36,7 @@ export function join<A>(ta: Identity<Identity<A>>): Identity<A> {

export function chain<A, I>(
fati: (a: A) => Identity<I>,
): ((ta: Identity<A>) => Identity<I>) {
): (ta: Identity<A>) => Identity<I> {
return fati;
}

Expand Down
Loading

0 comments on commit 931c1d5

Please sign in to comment.