Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
fix: colocate utility types and hkts
Browse files Browse the repository at this point in the history
  • Loading branch information
baetheus committed Oct 8, 2020
1 parent 8e9f4e1 commit 1a9f8c2
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 60 deletions.
2 changes: 1 addition & 1 deletion array.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";

import * as D from "./derivations.ts";

Expand Down
4 changes: 2 additions & 2 deletions datum.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type * as TC from "./type_classes.ts";
import type { _ } from "./hkts.ts";
import type { _, Lazy } from "./types.ts";

import { createSequenceTuple, createSequenceStruct } from "./sequence.ts";
import { identity, isNotNil, Lazy } from "./fns.ts";
import { identity, isNotNil } from "./fns.ts";
import * as D from "./derivations.ts";

/***************************************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions datum_either.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as TC from "./type_classes.ts";
import type { _, _0, _1 } from "./hkts.ts";
import type { _, _0, _1, Lazy, Fn } from "./types.ts";

import { Fn, identity, isNotNil, Lazy } from "./fns.ts";
import { identity, isNotNil } from "./fns.ts";
import * as DA from "./datum.ts";
import * as E from "./either.ts";
import * as D from "./derivations.ts";
Expand Down
2 changes: 1 addition & 1 deletion decode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";
import type * as TC from "./type_classes.ts";

import { createPipeableMonad } from "./derivations.ts";
Expand Down
13 changes: 11 additions & 2 deletions either.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import type * as TC from "./type_classes.ts";
import type { $, _0, _1, _2, Fix } from "./hkts.ts";
import type {
$,
_0,
_1,
_2,
Fix,
Lazy,
Predicate,
Refinement,
} from "./types.ts";

import { createSequenceStruct, createSequenceTuple } from "./sequence.ts";
import { isNotNil, Lazy, Predicate, Refinement } from "./fns.ts";
import { isNotNil } from "./fns.ts";
import * as D from "./derivations.ts";

/***************************************************************************************************
Expand Down
20 changes: 1 addition & 19 deletions fns.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
/***************************************************************************************************
* @section Types
**************************************************************************************************/

export type Fn<AS extends unknown[], B> = (...as: AS) => B;

export type Nil = undefined | null;

export interface Lazy<A> {
(): A;
}

export interface Predicate<A> {
(a: A): boolean;
}

export interface Refinement<A, B extends A> {
(a: A): a is B;
}
import type { Nil, Fn, Lazy } from "./types.ts";

/***************************************************************************************************
* @section Guards
Expand Down
2 changes: 1 addition & 1 deletion guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";

import { pipe, Refinement } from "./fns.ts";
import * as S from "./schemable.ts";
Expand Down
2 changes: 1 addition & 1 deletion identity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";

import { createMonad, createPipeableMonad } from "./derivations.ts";
import { createSequenceTuple, createSequenceStruct } from "./sequence.ts";
Expand Down
2 changes: 1 addition & 1 deletion io.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";

import { createSequenceStruct, createSequenceTuple } from "./sequence.ts";
import { constant, pipe } from "./fns.ts";
Expand Down
2 changes: 1 addition & 1 deletion io_either.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { Fix, _, _0, _1 } from "./hkts.ts";
import type { Fix, _, _0, _1 } from "./types.ts";
import { constant, Lazy, pipe } from "./fns.ts";

import * as E from "./either.ts";
Expand Down
2 changes: 1 addition & 1 deletion iso.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1 } from "./hkts.ts";
import type { _0, _1 } from "./types.ts";

import * as O from "./option.ts";
import { constant, flow, identity } from "./fns.ts";
Expand Down
2 changes: 1 addition & 1 deletion lens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1 } from "./hkts.ts";
import type { _0, _1 } from "./types.ts";

import * as O from "./option.ts";
import type { Optional } from "./optional.ts";
Expand Down
4 changes: 2 additions & 2 deletions option.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type * as TC from "./type_classes.ts";
import type { $, _ } from "./hkts.ts";
import type { $, _, Lazy, Predicate } from "./types.ts";

import { createSequenceStruct, createSequenceTuple } from "./sequence.ts";
import { isNotNil, Lazy, Predicate } from "./fns.ts";
import { isNotNil } from "./fns.ts";
import * as D from "./derivations.ts";

/***************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
flow,
identity,
} from "./fns.ts";
import { _0, _1 } from "./hkts.ts";
import { _0, _1 } from "./types.ts";

/***************************************************************************************************
* @section Types
Expand Down
2 changes: 1 addition & 1 deletion prism.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1 } from "./hkts.ts";
import type { _0, _1 } from "./types.ts";

import * as L from "./lens.ts";
import * as O from "./option.ts";
Expand Down
2 changes: 1 addition & 1 deletion reader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1 } from "./hkts.ts";
import type { _0, _1 } from "./types.ts";

import { createSequenceStruct, createSequenceTuple } from "./sequence.ts";
import { identity, constant } from "./fns.ts";
Expand Down
2 changes: 1 addition & 1 deletion record.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { $, _ } from "./hkts.ts";
import type { $, _ } from "./types.ts";

import * as D from "./derivations.ts";

Expand Down
2 changes: 1 addition & 1 deletion schemable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { $, _ } from "./hkts.ts";
import type { $, _ } from "./types.ts";
import type { LS } from "./type_classes.ts";

/***************************************************************************************************
Expand Down
24 changes: 15 additions & 9 deletions sequence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { $, _, _0, _1 } from "./hkts.ts";
import type { $ } from "./types.ts";
import type { Apply, LS } from "./type_classes.ts";

import { _reduce } from "./array.ts";
Expand Down Expand Up @@ -55,18 +55,21 @@ type SequenceTuple<T, R extends NonEmptyArray<$<T, any[]>>, L extends LS = 1> =
// deno-fmt-ignore
type CreateSequenceTuple = {
<T, L extends 1>(A: Apply<T, L>):
<R extends NonEmptyArray<$<T, [any]>>>(...r: R) => SequenceTuple<T, R, L>;
<R extends NonEmptyArray<$<T, [unknown]>>>(...r: R) =>
SequenceTuple<T, R, L>;
<T, L extends 2>(A: Apply<T, L>):
<R extends NonEmptyArray<$<T, [any, any]>>>(...r: R) => SequenceTuple<T, R, L>;
<R extends NonEmptyArray<$<T, [unknown, unknown]>>>(...r: R) =>
SequenceTuple<T, R, L>;
<T, L extends 3>(A: Apply<T, L>):
<R extends NonEmptyArray<$<T, [any, any, any]>>>(...r: R) => SequenceTuple<T, R, L>;
<R extends NonEmptyArray<$<T, [unknown, unknown, unknown]>>>(...r: R) =>
SequenceTuple<T, R, L>;
};

/**
* Create a sequence over tuple function from Apply
*/
export const createSequenceTuple: CreateSequenceTuple = <T>(A: Apply<T>) =>
<R extends NonEmptyArray<$<T, [any]>>>(
<R extends NonEmptyArray<$<T, [unknown]>>>(
...r: R
): SequenceTuple<T, R> => {
const [head, ...tail] = r;
Expand Down Expand Up @@ -96,15 +99,18 @@ type SequenceStruct<T, R extends Record<string, $<T, any[]>>, L extends LS = 1>
// deno-fmt-ignore
type CreateSequenceStruct = {
<T, L extends 1>(A: Apply<T, L>):
<R extends Record<string, $<T, [any]>>>(r: NonEmptyRecord<R>) => SequenceStruct<T, R, L>;
<R extends Record<string, $<T, [any]>>>(r: NonEmptyRecord<R>) =>
SequenceStruct<T, R, L>;
<T, L extends 2>(A: Apply<T, L>):
<R extends Record<string, $<T, [any, any]>>>(r: NonEmptyRecord<R>) => SequenceStruct<T, R, L>;
<R extends Record<string, $<T, [any, any]>>>(r: NonEmptyRecord<R>) =>
SequenceStruct<T, R, L>;
<T, L extends 3>(A: Apply<T, L>):
<R extends Record<string, $<T, [any, any, any]>>>(r: NonEmptyRecord<R>) => SequenceStruct<T, R, L>;
<R extends Record<string, $<T, [any, any, any]>>>(r: NonEmptyRecord<R>) =>
SequenceStruct<T, R, L>;
};

export const createSequenceStruct: CreateSequenceStruct = <T>(A: Apply<T>) =>
<R extends Record<string, $<T, [any]>>>(
<R extends Record<string, $<T, any[]>>>(
r: NonEmptyRecord<R>,
): SequenceStruct<T, R> => {
const keys = Object.keys(r);
Expand Down
2 changes: 1 addition & 1 deletion state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1 } from "./hkts.ts";
import type { _0, _1 } from "./types.ts";

import * as D from "./derivations.ts";
import { flow } from "./fns.ts";
Expand Down
2 changes: 1 addition & 1 deletion task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { _ } from "./hkts.ts";
import type { _ } from "./types.ts";

import { createMonad, createPipeableMonad } from "./derivations.ts";
import { createSequenceTuple, createSequenceStruct } from "./sequence.ts";
Expand Down
4 changes: 2 additions & 2 deletions task_either.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as TC from "./type_classes.ts";
import type { _0, _1, _2, _3 } from "./hkts.ts";
import { Lazy, pipe } from "./fns.ts";
import type { _0, _1, Lazy } from "./types.ts";
import { pipe } from "./fns.ts";

import * as E from "./either.ts";
import * as T from "./task.ts";
Expand Down
2 changes: 1 addition & 1 deletion testing/derivations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

import type { _ } from "../hkts.ts";
import type { _ } from "../types.ts";

import * as O from "../option.ts";
import { createMonad } from "../derivations.ts";
Expand Down
2 changes: 1 addition & 1 deletion these.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { Fix, _0, _1 } from "./hkts.ts";
import type { Fix, _0, _1 } from "./types.ts";

import * as D from "./derivations.ts";
import * as E from "./either.ts";
Expand Down
2 changes: 1 addition & 1 deletion traversal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { $, _0, _1 } from "./hkts.ts";
import type { $, _0, _1 } from "./types.ts";

import * as I from "./identity.ts";
import * as P from "./prism.ts";
Expand Down
2 changes: 1 addition & 1 deletion tree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as TC from "./type_classes.ts";
import type { $, _ } from "./hkts.ts";
import type { $, _ } from "./types.ts";

import * as A from "./array.ts";
import * as D from "./derivations.ts";
Expand Down
3 changes: 1 addition & 2 deletions type_classes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Predicate } from "./fns.ts";
import type { $ } from "./hkts.ts";
import type { $, Predicate } from "./types.ts";

/***************************************************************************************************
* Type Classes
Expand Down
20 changes: 19 additions & 1 deletion hkts.ts → types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import type { Refinement } from "./fns.ts";
/***************************************************************************************************
* @section Utility Types
**************************************************************************************************/

export type Fn<AS extends unknown[], B> = (...as: AS) => B;

export type Nil = undefined | null;

export interface Lazy<A> {
(): A;
}

export interface Predicate<A> {
(a: A): boolean;
}

export interface Refinement<A, B extends A> {
(a: A): a is B;
}

/***************************************************************************************************
* @section Hole Types
Expand Down

0 comments on commit 1a9f8c2

Please sign in to comment.