Skip to content

Commit

Permalink
Convert Prop
Browse files Browse the repository at this point in the history
  • Loading branch information
alex.gill@penna.com committed Dec 17, 2018
1 parent 6f8e3e7 commit e28e007
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MaybeSelector } from './MaybeSelector'
import { Selector } from './Selector'
import { MaybeConverter } from './MaybeConverter'
import { Converter } from './Converter'
import { GetPropOverloads, Prop } from './Prop'
import { PropOverloads, Prop } from './Prop'
import { Extension } from './Extension';
import { Memoize } from './Memoize';
import { Debug } from './Debug';
Expand Down Expand Up @@ -45,7 +45,7 @@ export type Get<A, B, Params extends {} = {}> = GetSignature<A, B, Params> & {
choose: ChooseOverloads<Dimensionality.Single, Structure.Get, A, B, Params>
ifDefined: IfDefinedOverloads<Dimensionality.Single, Structure.Get, A, B, Params>
combine: GetCombine<A, B, Params>
prop: GetPropOverloads<A, B, Params>
prop: PropOverloads<Dimensionality.Single, Structure.Get, A, B, Params>
mapParams: <P2 extends {}>(map: (p2: P2) => Params) => Get<A, B, P2>
addParam: <P extends string, V = string>(p: P) => Get<A, B, Params & Property<P, V>>
withParams: <P2 extends Partial<Params>>(params: P2) => Get<A, B, Subtract<Params, P2>>
Expand Down
4 changes: 2 additions & 2 deletions src/MaybeGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MaybeSelector } from './MaybeSelector'
import { Selector } from './Selector'
import { MaybeConverter } from './MaybeConverter'
import { Converter } from './Converter'
import { GetPropOverloads, Prop } from './Prop'
import { PropOverloads, Prop } from './Prop'
import { Extension } from './Extension';
import { Memoize } from './Memoize';
import { Debug } from './Debug';
Expand Down Expand Up @@ -45,7 +45,7 @@ export type MaybeGet<A, B, Params extends {} = {}> = MaybeGetSignature<A, B, Par
choose: ChooseOverloads<Dimensionality.Maybe, Structure.Get, A, B, Params>
ifDefined: IfDefinedOverloads<Dimensionality.Maybe, Structure.Get, A, B, Params>
combine: MaybeGetCombine<A, B, Params>
prop: GetPropOverloads<A, B, Params>
prop: PropOverloads<Dimensionality.Maybe, Structure.Get, A, B, Params>
mapParams: <P2 extends {}>(map: (p2: P2) => Params) => MaybeGet<A, B, P2>
addParam: <P extends string, V = string>(p: P) => MaybeGet<A, B, Params & Property<P, V>>
withParams: <P2 extends Partial<Params>>(params: P2) => MaybeGet<A, B, Subtract<Params, P2>>
Expand Down
4 changes: 2 additions & 2 deletions src/MaybeSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Composable } from './Composable'
import { Selector } from './Selector'
import { MaybeConverter } from './MaybeConverter'
import { Converter } from './Converter'
import { MaybeSelectorPropOverloads, Prop } from './Prop'
import { PropOverloads, Prop } from './Prop'
import { IndexBy, IndexByOverloads } from './IndexBy'
import { Choose, ChooseOverloads } from './Choose';
import { Extension } from './Extension';
Expand Down Expand Up @@ -35,7 +35,7 @@ export interface MaybeSelector<A, B, Params extends {} = {}> {
set: Set<A, B, Params>
modify: Modify<A, B, Params>
compose: MaybeSelectorCompose<A, B, Params>
prop: MaybeSelectorPropOverloads<A, B, Params>
prop: PropOverloads<Dimensionality.Maybe, Structure.Select, A, B, Params>
indexBy: IndexByOverloads<Dimensionality.Maybe, Structure.Select, A, B, Params>
choose: ChooseOverloads<Dimensionality.Maybe, Structure.Select, A, B, Params>
ifDefined: IfDefinedOverloads<Dimensionality.Maybe, Structure.Select, A, B, Params>
Expand Down
36 changes: 11 additions & 25 deletions src/Prop.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
import { Selector } from './Selector'
import { MaybeSelector } from './MaybeSelector'
import { Get } from './Get'
import { Set } from './Set'
import { MaybeGet } from './MaybeGet'
import { Composable } from "./Composable"
import { Dimensionality, Structure } from "./Discriminants";

export interface MaybeGetPropOverloads<A, B, Params extends {} = {}> {
<K1 extends keyof B>(key: K1): MaybeGet<A, B[K1], Params>
<K1 extends keyof B, K2 extends keyof B[K1]>(k1: K1, k2: K2): MaybeGet<A, B[K1][K2], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2]>(k1: K1, k2: K2, k3: K3): MaybeGet<B, B[K1][K2][K3], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2], K4 extends keyof B[K1][K2][K3]>(k1: K1, k2: K2, k3: K3): MaybeGet<B, B[K1][K2][K3][K4], Params>
}
export type PropOverloads<D extends Dimensionality, S extends Structure, A, B, Params extends {}> = {
<K1 extends keyof B>(key: K1)
: Composable.ComposeResult<A, B[K1], Params, D, Dimensionality.Single, S, Structure.Select>

export interface GetPropOverloads<A, B, Params extends {} = {}> {
<K1 extends keyof B>(key: K1): Get<A, B[K1], Params>
<K1 extends keyof B, K2 extends keyof B[K1]>(k1: K1, k2: K2): Get<A, B[K1][K2], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2]>(k1: K1, k2: K2, k3: K3): Get<B, B[K1][K2][K3], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2], K4 extends keyof B[K1][K2][K3]>(k1: K1, k2: K2, k3: K3): Get<B, B[K1][K2][K3][K4], Params>
}
<K1 extends keyof B, K2 extends keyof B[K1]>(k1: K1, k2: K2)
: Composable.ComposeResult<A, B[K1][K2], Params, D, Dimensionality.Single, S, Structure.Select>

export interface SelectorPropOverloads<A, B, Params extends {} = {}> {
<K1 extends keyof B>(key: K1): Selector<A, B[K1], Params>
<K1 extends keyof B, K2 extends keyof B[K1]>(k1: K1, k2: K2): Selector<A, B[K1][K2], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2]>(k1: K1, k2: K2, k3: K3): Selector<B, B[K1][K2][K3], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2], K4 extends keyof B[K1][K2][K3]>(k1: K1, k2: K2, k3: K3): Selector<B, B[K1][K2][K3][K4], Params>
}
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2]>(k1: K1, k2: K2, k3: K3)
: Composable.ComposeResult<A, B[K1][K2][K3], Params, D, Dimensionality.Single, S, Structure.Select>

export interface MaybeSelectorPropOverloads<A, B, Params extends {} = {}> {
<K1 extends keyof B>(key: K1): MaybeSelector<A, B[K1], Params>
<K1 extends keyof B, K2 extends keyof B[K1]>(k1: K1, k2: K2): MaybeSelector<A, B[K1][K2], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2]>(k1: K1, k2: K2, k3: K3): MaybeSelector<B, B[K1][K2][K3], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2], K4 extends keyof B[K1][K2][K3]>(k1: K1, k2: K2, k3: K3): MaybeSelector<B, B[K1][K2][K3][K4], Params>
<K1 extends keyof B, K2 extends keyof B[K1], K3 extends keyof B[K1][K2], K4 extends keyof B[K1][K2][K3]>(k1: K1, k2: K2, k3: K3, k4: K4)
: Composable.ComposeResult<A, B[K1][K2][K3][K4], Params, D, Dimensionality.Single, S, Structure.Select>
}

export namespace Prop {
Expand Down
4 changes: 2 additions & 2 deletions src/Root.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IndexBy, IndexByOverloads } from "./IndexBy";
import { SelectorPropOverloads, Prop } from "./Prop";
import { PropOverloads, Prop } from "./Prop";
import { MaybeConverter } from "./MaybeConverter";
import { Choose } from "./Choose";
import { Extension } from "./Extension";
Expand All @@ -9,7 +9,7 @@ import { Dimensionality, Structure } from './Discriminants';

export interface Root<A> {
indexBy: IndexByOverloads<Dimensionality.Single, Structure.Convert, A, A, {}>
prop: SelectorPropOverloads<A, A>
prop: PropOverloads<Dimensionality.Single, Structure.Convert, A, A, {}>
choose<B extends A>(typeGuard: (a: A) => a is B): MaybeConverter<A, B>
extend: (newExt: Extension) => Root<A>
memoize: () => Root<A>
Expand Down
4 changes: 2 additions & 2 deletions src/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MaybeSelector } from './MaybeSelector'
import { MaybeConverter } from './MaybeConverter'
import { Converter } from './Converter'
import { Composable } from './Composable'
import { SelectorPropOverloads, Prop } from './Prop'
import { PropOverloads, Prop } from './Prop'
import { IndexBy, IndexByOverloads } from './IndexBy';
import { Choose, ChooseOverloads } from './Choose';
import { Extension } from './Extension';
Expand Down Expand Up @@ -34,7 +34,7 @@ export interface Selector<A, B, Params extends {} = {}> {
set: Set<A, B, Params>
modify: Modify<A, B, Params>
compose: SelectorCompose<A, B, Params>
prop: SelectorPropOverloads<A, B, Params>
prop: PropOverloads<Dimensionality.Single, Structure.Select, A, B, Params>
indexBy: IndexByOverloads<Dimensionality.Single, Structure.Select, A, B, Params>
choose: ChooseOverloads<Dimensionality.Single, Structure.Select, A, B, Params>
ifDefined: IfDefinedOverloads<Dimensionality.Single, Structure.Select, A, B, Params>
Expand Down

0 comments on commit e28e007

Please sign in to comment.