-
Notifications
You must be signed in to change notification settings - Fork 2
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 #17 from anthonyjoeseph/array-index
Array & Record index
- Loading branch information
Showing
45 changed files
with
1,025 additions
and
416 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,25 @@ | ||
# Build (tail recursive) | ||
|
||
```ts | ||
_Obj1 = { a: { b: number, x: boolean }, c: { d: { e: string } } } | ||
Obj1 = [ | ||
{ path: ['a']; value: { b: number, x: boolean} }, | ||
{ path: ['c']; value: { d: { e: string } } | ||
] | ||
Output1 = ['a'] | ['c'] | ||
| | ||
V | ||
Obj2 = [ | ||
{ path: ['a', 'b']; value: number }, | ||
{ path: ['a', 'x']; value: boolean } | ||
{ path: ['c', 'd']; value: { e: string } } | ||
] | ||
Output2 = ['a', 'b'] | ['a', 'x'] | ['c', 'd'] | ||
| | ||
V | ||
Obj3 = [ | ||
{ path: ['c', 'd', 'e']; value: string } | ||
] | ||
Output3 = ['c', 'd', 'e'] | ||
|
||
``` |
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import type { Option } from "fp-ts/Option"; | ||
import type { AtPath } from "../util/AtPath"; | ||
import type { Build } from "../util/Build"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
import type { Paths } from "../util/Paths"; | ||
import type { GiveOpt, HasOptional } from "../util/predicates"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { Segments } from "../util/segments"; | ||
|
||
export type Get = < | ||
Infer, | ||
Path extends unknown extends Infer ? string : Paths<Infer>, | ||
Ret extends unknown extends Infer ? unknown : GiveOpt<AtPath<Infer, AddNullSegments<Path>>, AddNullSegments<Path>> | ||
Ret extends unknown extends Infer ? unknown : GiveOpt<AtPath<Infer, S>, S>, | ||
S extends unknown[] = Segments<Path> | ||
>( | ||
path: Path & string | ||
path: Path & string, | ||
...indicies: IndiciesForPath<S> | ||
) => unknown extends Infer | ||
? unknown extends Ret | ||
? <Constructed extends Build<Path, unknown>>( | ||
obj: Constructed | ||
) => GiveOpt<AtPath<Constructed, AddNullSegments<Path>>, AddNullSegments<Path>> | ||
: true extends HasOptional<Path> | ||
? (obj: Build<Path, [Ret] extends [Option<infer A>] ? A : unknown>) => Ret | ||
: (obj: Build<Path, Ret>) => Ret | ||
? <Constructed extends Build<S, unknown>>(obj: Constructed) => GiveOpt<AtPath<Constructed, S>, S> | ||
: true extends HasOptional<S> | ||
? (obj: Build<S, [Ret] extends [Option<infer A>] ? A : unknown>) => Ret | ||
: (obj: Build<S, Ret>) => Ret | ||
: (obj: Infer) => Ret; |
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,10 +1,14 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { AtPath } from "../util/AtPath"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { Segments } from "../util/segments"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
|
||
export type Modify = <Infer, Path extends Paths<Infer>>( | ||
export type Modify = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
S extends unknown[] = Segments<Path>, | ||
A = AtPath<Infer, S, "no-traversals"> | ||
>( | ||
path: Path & string, | ||
modFunc: ( | ||
v: AtPath<Infer, AddNullSegments<Path>, "no-traversals"> | ||
) => AtPath<Infer, AddNullSegments<Path>, "no-traversals"> | ||
...args: [...indicies: IndiciesForPath<S>, modFunc: (v: A) => A] | ||
) => (a: Infer) => Infer; |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import type { AtPath } from "../util/AtPath"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
import type { Paths } from "../util/Paths"; | ||
import type { GiveOpt } from "../util/predicates"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { Segments } from "../util/segments"; | ||
|
||
export type ModifyOption = <Infer, Path extends Paths<Infer>>( | ||
export type ModifyOption = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
S extends unknown[] = Segments<Path>, | ||
A = AtPath<Infer, S, "no-traversals"> | ||
>( | ||
path: Path & string, | ||
modFunc: ( | ||
v: AtPath<Infer, AddNullSegments<Path>, "no-traversals"> | ||
) => AtPath<Infer, AddNullSegments<Path>, "no-traversals"> | ||
) => (a: Infer) => GiveOpt<Infer, AddNullSegments<Path>>; | ||
...args: [...indicies: IndiciesForPath<S>, modFunc: (v: A) => A] | ||
) => (a: Infer) => GiveOpt<Infer, 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,10 +1,17 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { Build } from "../util/Build"; | ||
import type { ApplyTraversals, AtPath } from "../util/AtPath"; | ||
import type { GiveOpt } from "../util/predicates"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { AtPath } from "../util/AtPath"; | ||
import type { GiveOpt, HasIndexedAccess } from "../util/predicates"; | ||
import type { Segments } from "../util/segments"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
|
||
export type ModifyOptionW = <Infer, Path extends Paths<Infer>, RetVal>( | ||
export type ModifyOptionW = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
RetVal, | ||
S extends unknown[] = Segments<Path>, | ||
A = AtPath<Infer, S, "no-traversals"> | ||
>( | ||
path: Path & string, | ||
modFunc: (v: AtPath<Infer, AddNullSegments<Path>, "no-traversals">) => RetVal | ||
) => (a: Infer) => GiveOpt<ApplyTraversals<Build<Path, RetVal, Infer>, Path>, Path>; | ||
...args: [...indicies: IndiciesForPath<S>, modFunc: (v: A) => RetVal] | ||
) => (a: Infer) => GiveOpt<Build<S, true extends HasIndexedAccess<S> ? RetVal | AtPath<Infer, S> : RetVal, Infer>, 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,14 +1,17 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { Build } from "../util/Build"; | ||
import type { ApplyTraversals, AtPath } from "../util/AtPath"; | ||
import type { HasOptional } from "../util/predicates"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { AtPath } from "../util/AtPath"; | ||
import type { HasIndexedAccess } from "../util/predicates"; | ||
import type { Segments } from "../util/segments"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
|
||
export type ModifyW = <Infer, Path extends Paths<Infer>, RetVal>( | ||
export type ModifyW = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
RetVal, | ||
S extends unknown[] = Segments<Path>, | ||
A = AtPath<Infer, S, "no-traversals"> | ||
>( | ||
path: Path & string, | ||
modFunc: (v: AtPath<Infer, AddNullSegments<Path>, "no-traversals">) => RetVal | ||
) => ( | ||
a: Infer | ||
) => true extends HasOptional<Path> | ||
? ApplyTraversals<Build<Path, RetVal | AtPath<Infer, AddNullSegments<Path>>, Infer>, AddNullSegments<Path>> | ||
: ApplyTraversals<Build<Path, RetVal, Infer>, AddNullSegments<Path>>; | ||
...args: [...indicies: IndiciesForPath<S>, modFunc: (v: A) => RetVal] | ||
) => (a: Infer) => Build<S, true extends HasIndexedAccess<S> ? RetVal | AtPath<Infer, S> : RetVal, Infer>; |
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,6 +1,7 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { Build } from "../util/Build"; | ||
import { Segments } from "../util/segments"; | ||
|
||
export type Remove = <Infer, Path extends Paths<Infer, "dynamic">>( | ||
fullPath: Path & string | ||
) => (a: Infer) => Build<Path, unknown, Infer, string, "remove">; | ||
) => (a: Infer) => Build<Segments<Path>, unknown, Infer, string, "remove">; |
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,9 +1,14 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { Build } from "../util/Build"; | ||
import { AtPath } from "../util/AtPath"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import { Segments } from "../util/segments"; | ||
|
||
export type Rename = <Infer, Path extends Paths<Infer, "dynamic">, NewKey extends string>( | ||
export type Rename = < | ||
Infer, | ||
Path extends Paths<Infer, "dynamic">, | ||
NewKey extends string, | ||
S extends unknown[] = Segments<Path> | ||
>( | ||
fullPath: Path & string, | ||
newKey: NewKey | ||
) => (a: Infer) => Build<Path, AtPath<Infer, AddNullSegments<Path>>, Infer, NewKey>; | ||
) => (a: Infer) => Build<S, AtPath<Infer, S>, Infer, NewKey>; |
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,8 +1,14 @@ | ||
import type { AtPath } from "../util/AtPath"; | ||
import { IndiciesForPath } from "../util/indicies"; | ||
import type { Paths } from "../util/Paths"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import { Segments } from "../util/segments"; | ||
|
||
export type Set = <Infer, Path extends Paths<Infer>, Val extends AtPath<Infer, AddNullSegments<Path>, "no-traversals">>( | ||
export type Set = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
Val extends AtPath<Infer, S, "no-traversals">, | ||
S extends unknown[] = Segments<Path> | ||
>( | ||
path: Path & string, | ||
val: Val | ||
...args: [...indicies: IndiciesForPath<S>, val: Val] | ||
) => (obj: Infer) => Infer; |
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,13 +1,15 @@ | ||
import type { AtPath } from "../util/AtPath"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
import type { Paths } from "../util/Paths"; | ||
import type { GiveOpt } from "../util/predicates"; | ||
import { AddNullSegments } from "../util/segments"; | ||
import type { Segments } from "../util/segments"; | ||
|
||
export type SetOption = < | ||
Infer, | ||
Path extends Paths<Infer>, | ||
Val extends AtPath<Infer, AddNullSegments<Path>, "no-traversals"> | ||
Val extends AtPath<Infer, S, "no-traversals">, | ||
S extends unknown[] = Segments<Path> | ||
>( | ||
path: Path & string, | ||
val: Val | ||
) => (obj: Infer) => GiveOpt<Infer, Path>; | ||
...args: [...indicies: IndiciesForPath<S>, val: Val] | ||
) => (obj: Infer) => GiveOpt<Infer, 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,8 +1,18 @@ | ||
import type { Paths } from "../util/Paths"; | ||
import type { Build } from "../util/Build"; | ||
import type { IndiciesForPath } from "../util/indicies"; | ||
import type { HasIndexedAccess } from "../util/predicates"; | ||
import type { Segments } from "../util/segments"; | ||
import type { AtPath } from "../util/AtPath"; | ||
|
||
export type Upsert = <Infer, Path extends Paths<Infer, "upsert">, Final extends string, Val>( | ||
export type Upsert = < | ||
Infer, | ||
Path extends Paths<Infer, "upsert">, | ||
Final extends string, | ||
Val, | ||
S extends unknown[] = Segments<Path> | ||
>( | ||
path: Path & string, | ||
final: Final, | ||
val: Val | ||
) => (a: Infer) => Build<`${Extract<Path, string>}.${Final}`, Val, Infer>; | ||
...args: [...indicies: IndiciesForPath<S>, val: Val] | ||
) => (a: Infer) => Build<[...S, Final], true extends HasIndexedAccess<S> ? AtPath<Infer, S> | Val : Val, Infer>; |
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
Oops, something went wrong.