Full Code of pelotom/hkts for AI

master 786840c7d6fe cached
13 files
22.4 KB
7.2k tokens
40 symbols
1 requests
Download .txt
Repository: pelotom/hkts
Branch: master
Commit: 786840c7d6fe
Files: 13
Total size: 22.4 KB

Directory structure:
gitextract_mg5a2za2/

├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .travis.yml
├── .vscode/
│   └── settings.json
├── LICENSE
├── README.md
├── jest.config.js
├── package.json
├── src/
│   ├── index.spec.ts
│   ├── index.ts
│   └── static-land.ts
└── tsconfig.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
coverage
lib
node_modules

================================================
FILE: .prettierignore
================================================
coverage
lib
package.json
README.md
tsconfig.json

================================================
FILE: .prettierrc.yml
================================================
arrowParens: avoid
bracketSpacing: true
printWidth: 100
semi: true
tabWidth: 2
trailingComma: all
singleQuote: true


================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
  - node
cache: yarn
script:
  - yarn test
  - yarn format
after_success: cat ./coverage/lcov.info | ./node_modules/.bin/coveralls

================================================
FILE: .vscode/settings.json
================================================
{
  "typescript.tsdk": "node_modules/typescript/lib",
  "editor.codeActionsOnSave": {
    "source.organizeImports": true
  },
  "editor.formatOnSave": true
}


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2018 Tom Crockett

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



================================================
FILE: README.md
================================================
# HKTS - Higher-Kinded TypeScript [![Build Status](https://travis-ci.com/pelotom/hkts.svg?branch=master)](https://travis-ci.com/pelotom/hkts)

## Overview

TypeScript [doesn't directly support higher-kinded types yet](https://github.com/Microsoft/TypeScript/issues/1213), but various attempts have been made to simulate them (see [related work](https://github.com/pelotom/hkts/blob/master/README.md#related-work) at the bottom). This project presents a new, greatly simplified approach to encoding HKTs using the power of conditional types.

The idea is that, although we can't truly abstract over a type constructor `type T<A> = ...`, we _can_ abstract over the result `T<_>` of applying it to a special placeholder type `_`. Then, if we can somehow substitute all instances of `_` within a type, we effectively have the ability to "apply" `T` at arbitrary types. That is, we can abstract over `T`! And it turns out we can define a substitution operator `$<T, S>` which does just that.

Here's how we would use `$` to define the [static-land's `Functor` type class](https://github.com/rpominov/static-land/blob/master/docs/spec.md#functor):

```ts
interface Functor<T> {
  map: <A, B>(f: (x: A) => B, t: $<T, [A]>) => $<T, [B]>;
}
```

Then, supposing we have a `Maybe` type constructor

```ts
type Maybe<A> = { tag: 'none' } | { tag: 'some'; value: A };
const none: Maybe<never> = { tag: 'none' };
const some = <A>(value: A): Maybe<A> => ({ tag: 'some', value });
```

we can define a `Functor` instance for it like so, using the placeholder type `_`:

```ts
const MaybeFunctor: Functor<Maybe<_>> = {
  map: (f, maybe) => maybe.tag === 'none' ? none : some(f(maybe.value)),
};

// It works!
expect(MaybeFunctor.map(n => n + 1, some(42))).toEqual(some(43));
```

## Type classes and instance factories

This package defines [a set of interfaces](https://github.com/pelotom/hkts/blob/master/src/static-land.ts) corresponding to the the type classes of the [static-land spec](https://github.com/rpominov/static-land), as well as factory functions for producing instances thereof. For example, there is a `Monad` interface as well as a `Monad` function. The function takes as arguments only the minimum data (`of` and `chain`) needed to produce an implementation of the full `Monad` interface (which includes other derived methods like `map`, `ap` and `join`). So again using the `Maybe` type above, we can construct a `Monad` instance like so:

```ts
const MaybeMonad = Monad<Maybe<_>>({
  of: some,
  chain: (f, maybe) => maybe.tag === 'none' ? none : f(maybe.value),
});

// Use the `map` method, which we didn't have to define:
expect(MaybeMonad.map(n => n + 1, some(42))).toBe(some(43));
```

## Abstracting over kinds of higher arity

You may have noticed in the above example that `$` takes an array of substitution types as its second parameter. There are also placeholders `_0` (an alias for `_`), `_1`, `_2`, ..., `_<N>`. `$<T, S>` simultaneously replaces `_0` with `S[0]`, `_1` with `S[1]`, and so on, throughout `T`. This allows us to define, for example, `Bifunctor`, which abstracts over a type constructor of kind `(*, *) -> *`:

```ts
interface Bifunctor<T> {
  bimap: <A, B, C, D>(f: (x: A) => B, g: (x: C) => D, t: $<T, [A, C]>) => $<T, [B, D]>;
  // ...
}
```

Then given an `Either` type constructor

```ts
type Either<A, B> = { tag: 'left'; left: A } | { tag: 'right'; right: B };
const left = <A>(left: A): Either<A, never> => ({ tag: 'left', left });
const right = <B>(right: B): Either<never, B> => ({ tag: 'right', right });
```

a `Bifunctor` instance for it looks like

```ts
type EitherBifunctor: Bifunctor<Either<_0, _1>> = {
  bimap: (f, g, either) => (either.tag === 'left' ? left(f(either.left)) : right(g(either.right))),
};
```

## Fixing type parameters

Suppose we want to ignore one or more of the parameters of a type constructor for the purpose of making it an instance of a type class. For example we can make a `Monad` out of `Either` by ignoring its first parameter and using the second parameter as the "hole" of the monad. The way to do this is to make a polymorphic instance creation function which can produce a `Monad` instance _for any given left type `L`_:

```ts
const RightMonad = <L>() => Monad<Either<L, _>>({
  of: right,
  chain: (f, either) => either.tag === 'left' ? either : f(either.right),
});
```

## Known limitations

The type application operator `$` is able to transform most types correctly, including functions, however there are a few edge cases:
- Polymorphic functions will get nerfed. For example:
  ```ts
  type Id = <A>(x: A) => A
  type NerfedId = $<Id, []>;
  // type NerfedId = (x_0: {}) => {}
  ```
  Not what you wanted! Unfortunately TypeScript's conditional types don't currently allow analyzing and reconstructing the type parameters of a function ([this feature](https://github.com/Microsoft/TypeScript/issues/5453) might solve that).
- Tuples `[A, B, ...]` are transformed correctly up to size 10 (though we can add arbitrarily many more as needed), after which they will be transformed into an array `(A | B | ...)[]`. Correspondingly, functions of arity <= 10 are supported.
- In some cases the `join` method of `Monad` [must be supplied a type parameter](https://github.com/pelotom/hkts/blob/5ba4734bef74e9c2b8a10a75cb1de9ce230bde37/src/index.spec.ts#L23)... I've filed [an issue about this](https://github.com/Microsoft/TypeScript/issues/26807). The good news is it's still safe; you can't provide a _wrong_ type argument without getting an error.

## Related work

Other notable attempts to solve this problem:

- https://medium.com/@gcanti/higher-kinded-types-in-typescript-static-and-fantasy-land-d41c361d0dbe
- https://github.com/SimonMeskens/TypeProps


================================================
FILE: jest.config.js
================================================
module.exports = {
  clearMocks: true,
  coverageDirectory: 'coverage',
  globals: {
    'ts-jest': {
      tsConfigFile: 'tsconfig.json',
    },
  },
  moduleFileExtensions: ['ts', 'tsx', 'js'],
  testEnvironment: 'node',
  testMatch: ['<rootDir>/src/**/*.spec.ts'],
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
  },
};


================================================
FILE: package.json
================================================
{
  "name": "hkts",
  "version": "0.3.1",
  "description": "A simple encoding of higher-kinded types in TypeScript",
  "keywords:": [
    "typescript",
    "higher",
    "kinded",
    "types"
  ],
  "main": "./lib/index.js",
  "types": "./lib/index.d.ts",
  "author": "Thomas Crockett",
  "license": "MIT",
  "devDependencies": {
    "@types/jest": "^23.3.1",
    "jest": "^23.5.0",
    "prettier": "^1.14.2",
    "ts-jest": "^23.1.4",
    "typescript": "^3.0.1"
  },
  "scripts": {
    "build": "tsc",
    "format": "prettier $([ \"$CI\" == true ] && echo --list-different || echo --write) './**/*.{ts,tsx,js,json,css}'",
    "test": "jest $([ \"$CI\" == true ] && echo --no-cache --verbose --coverage)"
  }
}


================================================
FILE: src/index.spec.ts
================================================
import { Bifunctor, Monad, _, _0, _1 } from '.';

it('array', () => {
  const { map, join } = Monad<_[]>({
    of: x => [x],
    chain: (f, xs) => xs.map(f).reduce((xs, ys) => xs.concat(ys), []),
  });

  const result = map(n => n + 1, join([[42]]));
  expect(result).toEqual([43]);
});

it('maybe', () => {
  type Maybe<A> = { tag: 'none' } | { tag: 'some'; value: A };
  const none: Maybe<never> = { tag: 'none' };
  const some = <A>(value: A): Maybe<A> => ({ tag: 'some', value });

  const { map, join } = Monad<Maybe<_>>({
    of: some,
    chain: (f, maybe) => (maybe.tag === 'none' ? none : f(maybe.value)),
  });

  const result = map(n => n + 1, join<number>(some(some(42))));
  expect(result).toEqual(some(43));
});

it('list', () => {
  type List<A> = { tag: 'nil' } | { tag: 'cons'; head: A; tail: List<A> };
  const nil: List<never> = { tag: 'nil' };
  const cons = <A>(head: A, tail: List<A> = nil): List<A> => ({ tag: 'cons', head, tail });
  const concat = <A>(xs: List<A>, ys: List<A>): List<A> =>
    xs.tag === 'nil' ? ys : cons(xs.head, concat(xs.tail, ys));
  const chainList = <A, B>(f: (x: A) => List<B>, xs: List<A>): List<B> =>
    xs.tag === 'nil' ? nil : concat(f(xs.head), chainList(f, xs.tail));

  const { map, join } = Monad<List<_>>({
    of: x => cons(x, nil),
    chain: chainList,
  });

  const result = map(n => n + 1, join<number>(cons(cons(42))));
  expect(result).toEqual(cons(43));
});

describe('either', () => {
  type Either<A, B> = { tag: 'left'; left: A } | { tag: 'right'; right: B };
  const left = <A>(left: A): Either<A, never> => ({ tag: 'left', left });
  const right = <B>(right: B): Either<never, B> => ({ tag: 'right', right });

  it('bifunctor', () => {
    const { bimap, first, second } = Bifunctor<Either<_0, _1>>({
      bimap: (f, g, either) =>
        either.tag === 'left' ? left(f(either.left)) : right(g(either.right)),
    });

    const l = (x: number): boolean => !(x % 2);
    const r = (y: boolean): string => String(y);

    const input1: Either<number, boolean> = left(2);
    const result1 = bimap(l, r, input1);
    expect(result1).toEqual(left(true));

    const input2: Either<number, boolean> = right(true);
    const result2 = bimap(l, r, input2);
    expect(result2).toEqual(right('true'));

    expect(first(result2).map(x => !x, result2)).toEqual(right('true'));
    expect(second(result2).map(x => x.length, result2)).toEqual(right(4));
  });

  it('monad', () => {
    const RightMonad = <L>() =>
      Monad<Either<L, _>>({
        of: right,
        chain: (f, either) => (either.tag === 'left' ? either : f(either.right)),
      });

    const either = right(42);
    const result = RightMonad().map(n => n + 1, either);
    expect(result).toEqual(right(43));
  });
});


================================================
FILE: src/index.ts
================================================
declare const index: unique symbol;

/**
 * Placeholder representing an indexed type variable.
 */
export interface _<N extends number = 0> {
  [index]: N;
}
export type _0 = _<0>;
export type _1 = _<1>;
export type _2 = _<2>;
export type _3 = _<3>;
export type _4 = _<4>;
export type _5 = _<5>;
export type _6 = _<6>;
export type _7 = _<7>;
export type _8 = _<8>;
export type _9 = _<9>;

declare const fixed: unique symbol;

/**
 * Marks a type to be ignored by the application operator `$`. This is used to protect
 * bound type parameters.
 */
export interface Fixed<T> {
  [fixed]: T;
}

/**
 * Type application (simultaneously substitutes all placeholders within the target type)
 */
// prettier-ignore
export type $<T, S extends any[]> = (
  T extends Fixed<infer U> ? { [indirect]: U } :
  T extends _<infer N> ? { [indirect]: S[N] } :
  T extends undefined | null | boolean | string | number ? { [indirect]: T } :
  T extends (infer A)[] & { length: infer L } ? {
    [indirect]: L extends keyof TupleTable
      ? TupleTable<T, S>[L]
      : $<A, S>[]
  } :
  T extends (...x: infer I) => infer O ? { [indirect]: (...x: $<I, S>) => $<O, S> } :
  T extends object ? { [indirect]: { [K in keyof T]: $<T[K], S> } } :
  { [indirect]: T }
)[typeof indirect];

/**
 * Used as a level of indirection to avoid circularity errors.
 */
declare const indirect: unique symbol;

/**
 * Allows looking up the type for a tuple based on its `length`, instead of trying
 * each possibility one by one in a single long conditional.
 */
// prettier-ignore
type TupleTable<T extends any[] = any, S extends any[] = any> = {
  0: [];
  1: T extends [
      infer A0
    ] ? [
      $<A0, S>
    ] : never
  2: T extends [
      infer A0, infer A1
    ] ? [
      $<A0, S>, $<A1, S>
    ] : never
  3: T extends [
      infer A0, infer A1, infer A2
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>
    ] : never
  4: T extends [
      infer A0, infer A1, infer A2, infer A3
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>
    ] : never
  5: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>
    ] : never
  6: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4, infer A5
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>, $<A5, S>
    ] : never
  7: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4, infer A5, infer A6
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>, $<A5, S>, $<A6, S>
    ] : never
  8: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>, $<A5, S>, $<A6, S>, $<A7, S>
    ] : never
  9: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>, $<A5, S>, $<A6, S>, $<A7, S>, $<A8, S>
    ] : never
  10: T extends [
      infer A0, infer A1, infer A2, infer A3, infer A4, infer A5, infer A6, infer A7, infer A8, infer A9
    ] ? [
      $<A0, S>, $<A1, S>, $<A2, S>, $<A3, S>, $<A4, S>, $<A5, S>, $<A6, S>, $<A7, S>, $<A8, S>, $<A9, S>
    ] : never
}

export * from './static-land';


================================================
FILE: src/static-land.ts
================================================
import { $, _ } from '.';

export interface Setoid<T> {
  equals: (x: T, y: T) => boolean;
}

export interface Ord<T> extends Setoid<T> {
  lte: (x: T, y: T) => boolean;
}

export interface Semigroup<T> {
  concat: (x: T, y: T) => T;
}

export interface Monoid<T> extends Semigroup<T> {
  empty: () => T;
}

export interface Group<T> extends Monoid<T> {
  invert: (x: T) => T;
}

export interface Semigroupoid<T> {
  compose: <I, J, K>(tij: $<T, [I, J]>, tjk: $<T, [J, K]>) => $<T, [I, K]>;
}

export interface Category<T> extends Semigroupoid<T> {
  id: <I, J>() => $<T, [I, J]>;
}

export interface Filterable<T> {
  filter: <A>(pred: (x: A) => boolean, ta: $<T, [A]>) => $<T, [A]>;
}

export interface Functor<T> {
  map: <A, B>(f: (x: A) => B, t: $<T, [A]>) => $<T, [B]>;
}
export const Functor = <T>(spec: Functor<T>) => spec;

export interface Bifunctor<T> {
  bimap: <A, B, C, D>(f: (x: A) => B, g: (x: C) => D, t: $<T, [A, C]>) => $<T, [B, D]>;
  first: <A, B>(t: $<T, [A, B]>) => Functor<$<T, [_, B]>>;
  second: <A, B>(t: $<T, [A, B]>) => Functor<$<T, [A, _]>>;
}
export const Bifunctor = <T>({ bimap }: Pick<Bifunctor<T>, 'bimap'>): Bifunctor<T> => ({
  bimap,
  first: <A, B>(t: $<T, [A, B]>) => ({
    map: (f, u) => bimap(f, x => x, u),
  }),
  second: <A, B>(t: $<T, [A, B]>) => ({
    map: (f, u) => bimap(x => x, f, u),
  }),
});

export interface Contravariant<T> {
  contramap: <A, B>(f: (x: A) => B, t: $<T, [B]>) => $<T, [A]>;
}

export interface Profunctor<T> {
  promap: <A, B, C, D>(f: (x: A) => B, g: (x: C) => D, t: $<T, [B, C]>) => $<T, [A, D]>;
}

export interface Apply<T> extends Functor<T> {
  ap: <A, B>(tf: $<T, [(x: A) => B]>, ta: $<T, [A]>) => $<T, [B]>;
}

export interface Applicative<T> extends Apply<T> {
  of: <A>(x: A) => $<T, [A]>;
}
export const Applicative = <T>(spec: Pick<Applicative<T>, 'ap' | 'of'>): Applicative<T> => ({
  ...spec,
  map: (f, u) => spec.ap(spec.of(f), u),
});

export interface Alt<T> extends Functor<T> {
  alt: <A>(x: $<T, [A]>, y: $<T, [A]>) => $<T, [A]>;
}

export interface Plus<T> extends Alt<T> {
  zero: <A>() => $<T, [A]>;
}

export interface Alternative<T> extends Applicative<T>, Plus<T> {}

export interface Chain<T> extends Apply<T> {
  chain: <A, B>(f: (x: A) => $<T, [B]>, t: $<T, [A]>) => $<T, [B]>;
}
export const Chain = <T>(spec: Pick<Chain<T>, 'chain'> & Pick<Functor<T>, 'map'>): Chain<T> => ({
  ...spec,
  ap: (uf, ux) => spec.chain(f => spec.map(f, ux), uf),
});

export interface Monad<T> extends Applicative<T>, Chain<T> {
  join: <A>(tt: $<T, [$<T, [A]>]>) => $<T, [A]>;
}
export const Monad = <T>({
  of,
  chain,
}: Pick<Applicative<T>, 'of'> & Pick<Chain<T>, 'chain'>): Monad<T> => ({
  of,
  ...Chain({ chain, map: (f, t) => chain(x => of(f(x)), t) }),
  join: tt => chain(t => t, tt),
});

export interface Foldable<T> {
  reduce: <A, B>(f: (x: A, y: B) => A, x: A, u: $<T, [B]>) => A;
}

export interface Extend<T> extends Functor<T> {
  extend: <A, B>(f: (t: $<T, [A]>) => B, t: $<T, [A]>) => $<T, [B]>;
}

export interface Comonad<T> extends Extend<T> {
  extract: <a>(t: $<T, [a]>) => a;
}

export interface Traversable<T> extends Functor<T>, Foldable<T> {
  traverse: <U, A, B>(a: Applicative<U>, f: (x: A) => $<U, [B]>, t: $<T, [A]>) => $<U, [$<T, [B]>]>;
}


================================================
FILE: tsconfig.json
================================================
{
  "compilerOptions": {
    /* Basic Options */
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    // "lib": [],                             /* Specify library files to be included in the compilation. */
    // "allowJs": true,                       /* Allow javascript files to be compiled. */
    // "checkJs": true,                       /* Report errors in .js files. */
    // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
    "declaration": true,                      /* Generates corresponding '.d.ts' file. */
    // "declarationMap": true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */
    // "sourceMap": true,                     /* Generates corresponding '.map' file. */
    // "outFile": "./",                       /* Concatenate and emit output to single file. */
    "outDir": "lib",                          /* Redirect output structure to the directory. */
    // "rootDir": "./",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    // "composite": true,                     /* Enable project compilation */
    // "removeComments": true,                /* Do not emit comments to output. */
    // "noEmit": true,                        /* Do not emit outputs. */
    // "importHelpers": true,                 /* Import emit helpers from 'tslib'. */
    // "downlevelIteration": true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    // "noImplicitAny": true,                 /* Raise error on expressions and declarations with an implied 'any' type. */
    // "strictNullChecks": true,              /* Enable strict null checks. */
    // "strictFunctionTypes": true,           /* Enable strict checking of function types. */
    // "strictPropertyInitialization": true,  /* Enable strict checking of property initialization in classes. */
    // "noImplicitThis": true,                /* Raise error on 'this' expressions with an implied 'any' type. */
    // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */

    /* Additional Checks */
    // "noUnusedLocals": true,                /* Report errors on unused locals. */
    // "noUnusedParameters": true,            /* Report errors on unused parameters. */
    // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */
    // "noFallthroughCasesInSwitch": true,    /* Report errors for fallthrough cases in switch statement. */

    /* Module Resolution Options */
    // "moduleResolution": "node",            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    // "baseUrl": "./",                       /* Base directory to resolve non-absolute module names. */
    // "paths": {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
    // "rootDirs": [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
    // "typeRoots": [],                       /* List of folders to include type definitions from. */
    // "types": [],                           /* Type declaration files to be included in compilation. */
    // "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    // "preserveSymlinks": true,              /* Do not resolve the real path of symlinks. */

    /* Source Map Options */
    // "sourceRoot": "",                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "",                         /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Experimental Options */
    // "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
  }
}
Download .txt
gitextract_mg5a2za2/

├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .travis.yml
├── .vscode/
│   └── settings.json
├── LICENSE
├── README.md
├── jest.config.js
├── package.json
├── src/
│   ├── index.spec.ts
│   ├── index.ts
│   └── static-land.ts
└── tsconfig.json
Download .txt
SYMBOL INDEX (40 symbols across 3 files)

FILE: src/index.spec.ts
  type Maybe (line 14) | type Maybe<A> = { tag: 'none' } | { tag: 'some'; value: A };
  type List (line 28) | type List<A> = { tag: 'nil' } | { tag: 'cons'; head: A; tail: List<A> };
  type Either (line 46) | type Either<A, B> = { tag: 'left'; left: A } | { tag: 'right'; right: B };

FILE: src/index.ts
  type _ (line 6) | interface _<N extends number = 0> {
  type _0 (line 9) | type _0 = _<0>;
  type _1 (line 10) | type _1 = _<1>;
  type _2 (line 11) | type _2 = _<2>;
  type _3 (line 12) | type _3 = _<3>;
  type _4 (line 13) | type _4 = _<4>;
  type _5 (line 14) | type _5 = _<5>;
  type _6 (line 15) | type _6 = _<6>;
  type _7 (line 16) | type _7 = _<7>;
  type _8 (line 17) | type _8 = _<8>;
  type _9 (line 18) | type _9 = _<9>;
  type Fixed (line 26) | interface Fixed<T> {
  type $ (line 34) | type $<T, S extends any[]> = (
  type TupleTable (line 58) | type TupleTable<T extends any[] = any, S extends any[] = any> = {

FILE: src/static-land.ts
  type Setoid (line 3) | interface Setoid<T> {
  type Ord (line 7) | interface Ord<T> extends Setoid<T> {
  type Semigroup (line 11) | interface Semigroup<T> {
  type Monoid (line 15) | interface Monoid<T> extends Semigroup<T> {
  type Group (line 19) | interface Group<T> extends Monoid<T> {
  type Semigroupoid (line 23) | interface Semigroupoid<T> {
  type Category (line 27) | interface Category<T> extends Semigroupoid<T> {
  type Filterable (line 31) | interface Filterable<T> {
  type Functor (line 35) | interface Functor<T> {
  type Bifunctor (line 40) | interface Bifunctor<T> {
  type Contravariant (line 55) | interface Contravariant<T> {
  type Profunctor (line 59) | interface Profunctor<T> {
  type Apply (line 63) | interface Apply<T> extends Functor<T> {
  type Applicative (line 67) | interface Applicative<T> extends Apply<T> {
  type Alt (line 75) | interface Alt<T> extends Functor<T> {
  type Plus (line 79) | interface Plus<T> extends Alt<T> {
  type Alternative (line 83) | interface Alternative<T> extends Applicative<T>, Plus<T> {}
  type Chain (line 85) | interface Chain<T> extends Apply<T> {
  type Monad (line 93) | interface Monad<T> extends Applicative<T>, Chain<T> {
  type Foldable (line 105) | interface Foldable<T> {
  type Extend (line 109) | interface Extend<T> extends Functor<T> {
  type Comonad (line 113) | interface Comonad<T> extends Extend<T> {
  type Traversable (line 117) | interface Traversable<T> extends Functor<T>, Foldable<T> {
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (24K chars).
[
  {
    "path": ".gitignore",
    "chars": 25,
    "preview": "coverage\nlib\nnode_modules"
  },
  {
    "path": ".prettierignore",
    "chars": 49,
    "preview": "coverage\nlib\npackage.json\nREADME.md\ntsconfig.json"
  },
  {
    "path": ".prettierrc.yml",
    "chars": 116,
    "preview": "arrowParens: avoid\nbracketSpacing: true\nprintWidth: 100\nsemi: true\ntabWidth: 2\ntrailingComma: all\nsingleQuote: true\n"
  },
  {
    "path": ".travis.yml",
    "chars": 157,
    "preview": "language: node_js\nnode_js:\n  - node\ncache: yarn\nscript:\n  - yarn test\n  - yarn format\nafter_success: cat ./coverage/lcov"
  },
  {
    "path": ".vscode/settings.json",
    "chars": 158,
    "preview": "{\n  \"typescript.tsdk\": \"node_modules/typescript/lib\",\n  \"editor.codeActionsOnSave\": {\n    \"source.organizeImports\": true"
  },
  {
    "path": "LICENSE",
    "chars": 1080,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2018 Tom Crockett\n\nPermission is hereby granted, free of charge, to any person obta"
  },
  {
    "path": "README.md",
    "chars": 5742,
    "preview": "# HKTS - Higher-Kinded TypeScript [![Build Status](https://travis-ci.com/pelotom/hkts.svg?branch=master)](https://travis"
  },
  {
    "path": "jest.config.js",
    "chars": 325,
    "preview": "module.exports = {\n  clearMocks: true,\n  coverageDirectory: 'coverage',\n  globals: {\n    'ts-jest': {\n      tsConfigFile"
  },
  {
    "path": "package.json",
    "chars": 711,
    "preview": "{\n  \"name\": \"hkts\",\n  \"version\": \"0.3.1\",\n  \"description\": \"A simple encoding of higher-kinded types in TypeScript\",\n  \""
  },
  {
    "path": "src/index.spec.ts",
    "chars": 2757,
    "preview": "import { Bifunctor, Monad, _, _0, _1 } from '.';\n\nit('array', () => {\n  const { map, join } = Monad<_[]>({\n    of: x => "
  },
  {
    "path": "src/index.ts",
    "chars": 3266,
    "preview": "declare const index: unique symbol;\n\n/**\n * Placeholder representing an indexed type variable.\n */\nexport interface _<N "
  },
  {
    "path": "src/static-land.ts",
    "chars": 3262,
    "preview": "import { $, _ } from '.';\n\nexport interface Setoid<T> {\n  equals: (x: T, y: T) => boolean;\n}\n\nexport interface Ord<T> ex"
  },
  {
    "path": "tsconfig.json",
    "chars": 5328,
    "preview": "{\n  \"compilerOptions\": {\n    /* Basic Options */\n    \"target\": \"es5\",                          /* Specify ECMAScript tar"
  }
]

About this extraction

This page contains the full source code of the pelotom/hkts GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (22.4 KB), approximately 7.2k tokens, and a symbol index with 40 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!