-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ENvironmentSet/0.0.0-alpha.6
Merge works
- Loading branch information
Showing
35 changed files
with
12,469 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
.idea | ||
src | ||
docs | ||
.github | ||
CODE-OF-CONDUCT.md | ||
tsconfig.json | ||
.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TArray, Cons, Concat } from './Promoted/TArray'; | ||
import { TType } from './Primitive/TType'; | ||
|
||
export function cons<type extends TType, tarray extends TArray>(x: type, xs: tarray): Cons<type, tarray> { | ||
return [x, ...xs]; | ||
} | ||
|
||
export function head<type extends TType>([x]: Cons<type, TArray>): type { | ||
return x; | ||
} | ||
|
||
export function tail<tarray extends TArray>([_, ...xs]: Cons<TType, tarray>): tarray { | ||
return xs; | ||
} | ||
|
||
export function concat<xs extends TArray, ys extends TArray>(xs: xs, ys: ys): Concat<xs, ys> { | ||
return [...xs, ...ys]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HKT } from '../Primitive/HKT'; | ||
import { TType } from '../Primitive/TType'; | ||
import { TBoolean } from '../Promoted/TBoolean' | ||
|
||
export type If<condition extends boolean, then, orElse> = condition extends true ? then : orElse; | ||
export interface If_ extends HKT { | ||
params: [TBoolean, TType, TType]; | ||
condition: this['params'][0]; | ||
then: this['params'][1]; | ||
orElse: this['params'][2]; | ||
result: If<this['condition'], this['then'], this['orElse']>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { PhantomTypeParameter } from '../Primitive/PhantomTypeParameter'; | ||
import { TType } from '../Primitive/TType'; | ||
import { Apply, HKT } from '../Primitive/HKT'; | ||
|
||
type Context<context> = PhantomTypeParameter<'welltyped/state/context', context>; | ||
type Shadow<shadow> = PhantomTypeParameter<'welltyped/state/phantom', shadow>; | ||
type PickContext<state> = state extends Context<infer context> ? context : never; | ||
type PickShadow<shadow> = shadow extends Shadow<infer shadow> ? shadow : never; | ||
|
||
export interface Return<a extends TType> extends HKT { //@TODO: Make State strictly typed via kind polymorphism. | ||
params: [TType]; | ||
context: this['params'][0]; | ||
result: a & Context<this['context']> & Shadow<a>; | ||
} | ||
|
||
export interface Bind<state extends HKT, f extends HKT> extends HKT { | ||
params: [TType]; | ||
context: this['params'][0]; | ||
result: Apply<f, [PickShadow<state>, PickContext<this['context']>]> | ||
} | ||
|
||
export type Exec<state extends HKT, s extends TType> = Apply<state, [s]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,26 @@ | ||
import { Length, Reduce, AnyList, Map, Head, Tail, Snoc, Init, Cons, Scan } from './Promoted/List'; | ||
import { hnil } from './HList'; | ||
import { Z, S } from './Promoted/Nat'; | ||
import { Stuck } from './Primitive/Stuck'; | ||
import { HKT, Apply } from './Primitive/HKT'; | ||
import { DeriveGeneric, UnInitialized } from './Primitive/UnInitialized'; | ||
import { Intersection } from './Promoted/Intersection'; | ||
import { Flip } from './HKT/Flip'; | ||
import { If } from './Promoted/Bool'; | ||
import { Head, Length, Tail, TArray } from './Promoted/TArray'; | ||
import { Eq } from './Promoted/Eq'; | ||
import { Assert } from './Primitive/Assert'; | ||
|
||
export type AnyFunction = (...args: never) => unknown; | ||
export type TFunction = (...args: never) => unknown; | ||
type ConstraintVariadicFunction<f extends TFunction> | ||
= Eq<Length<Parameters<f>>, number> extends true ? [never] : never; | ||
|
||
type FilterByMatch<A, B> = { | ||
base: B; | ||
recursiveStep: If<[Eq<[Head<A>, Head<B>]>, FilterByMatch<Tail<A>, Tail<B>>, Cons<[Head<B>, FilterByMatch<Tail<A>, Tail<B>>]>]> | ||
}[Length<A> extends Z ? 'base' : 'recursiveStep']; | ||
export type Curried<f extends TFunction> | ||
= Length<Parameters<f>> extends 0 ? | ||
ReturnType<f> | ||
: (x: Head<Parameters<f>>) => Curried<(...args: Assert<Tail<Parameters<f>>, TArray>) => ReturnType<f>>; | ||
//@FIXME(Assert): IDK Why typescript can't catch that result of type well if there is variadic element with conditional type. | ||
|
||
interface ExtractNArgFunction<functionSignature extends AnyFunction> extends HKT { | ||
result: | ||
this['param'] extends AnyList ? | ||
FilterByMatch<this['param'], Parameters<functionSignature>> extends infer A ? | ||
A extends AnyList ? | ||
(...args: this['param']) => Curried<(...args: A) => ReturnType<functionSignature>> | ||
: Stuck | ||
: Stuck | ||
: Stuck; | ||
function setFunctionLength<f>(f: f, length: number): f { | ||
return Object.defineProperty(f, 'length', { value: length }); | ||
} | ||
|
||
type Subsequences<list extends AnyList> = Init<Scan<[ | ||
Flip<Snoc>, | ||
[], | ||
list | ||
]>>; | ||
|
||
interface _Curried extends HKT { | ||
result: this['param'] extends infer f ? | ||
f extends AnyFunction ? { | ||
base: Length<Parameters<f>> extends Z ? ReturnType<f> : f; | ||
recursiveStep: | ||
Reduce<[ | ||
Intersection, | ||
unknown, | ||
Map<[ | ||
ExtractNArgFunction<f> | ||
, | ||
Subsequences<Parameters<f>> | ||
]> | ||
]> | ||
}[Length<Parameters<f>> extends Z | S<Z> ? 'base' : 'recursiveStep'] | ||
: Stuck | ||
: Stuck; | ||
} | ||
type Curried<param = UnInitialized> = DeriveGeneric<_Curried, param>; | ||
|
||
export function curry<f extends AnyFunction>(f: f): Curried<f> { | ||
function _curry<applied extends AnyList>(applied: applied): Curried<f> { | ||
//@ts-expect-error @TODO: Type this code | ||
return (...args) => args.length + applied.length < f.length ? _curry(applied.concat(args)) : f(...(applied.concat(args))); | ||
} | ||
|
||
return _curry(hnil); | ||
} | ||
|
||
export type ElimWithConstraint<constraint extends HKT> = <R>(f: <A>(x: Apply<constraint, A>) => R) => R; | ||
export function makeElimWithConstraint<constraint extends HKT>(): <A>(x: Apply<constraint, A>) => ElimWithConstraint<constraint> { | ||
return x => f => f(x); | ||
//@FIXME: Is there any nature way not to use @ts-ignore? | ||
export function curry | ||
<f extends TFunction, constraint extends ConstraintVariadicFunction<f>> | ||
(f: f): Length<Parameters<f>> extends 0 ? f : Curried<f> { | ||
if (f.length < 2) return f as Length<Parameters<f>> extends 0 ? f : Curried<f>; | ||
//@ts-ignore | ||
else return x => curry(setFunctionLength((...args) => f(x, ...args), f.length - 1)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TObject, Set, Get } from './Promoted/TObject'; | ||
import { TString } from './Promoted/TString'; | ||
import { TType } from './Primitive/TType'; | ||
|
||
export function get<o extends TObject, k extends keyof o>(o: o, k: k): Get<o, k> { | ||
return o[k]; | ||
} | ||
|
||
export function set<o extends TObject, k extends TString, v extends TType>(o: o, k: k, v: v): Set<o, k, v> { | ||
return { ...o, [k]: v } as Set<o, k, v>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HKT } from '../Primitive/HKT'; | ||
import { TType } from '../Primitive/TType'; | ||
|
||
export type Eq<a, b> = | ||
(<T>() => T extends a ? never : never) extends (<T>() => T extends b ? never : never) ? | ||
true : false; | ||
export interface Eq_ extends HKT { | ||
params: [TType, TType]; | ||
a: this['params'][0]; | ||
b: this['params'][1]; | ||
result: Eq<this['a'], this['b']>; | ||
} |
Oops, something went wrong.