This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lens-like): support PseudoLens (lensIndex, lensProp) (#99)
- Loading branch information
Showing
31 changed files
with
365 additions
and
97 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
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,8 @@ | ||
import * as R_lensIndex from '../ramda/dist/src/lensIndex'; | ||
|
||
// @dts-jest:pass -> Lens<{}, {}[] | ArrayLike<{}>> | ||
declare const number: number; | ||
|
||
// @dts-jest:pass -> PseudoLens<0> | ||
R_lensIndex(0); | ||
// @dts-jest:pass -> Lens<number, number[]> | ||
R_lensIndex<number, number[]>(0); | ||
// @dts-jest:pass -> PseudoLens<number> | ||
R_lensIndex(number); |
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
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,37 @@ | ||
import { Lens } from '../ramda/dist/src/$types'; | ||
import { ManualLens, PseudoLens } from '../ramda/dist/src/$types'; | ||
import * as R_over from '../ramda/dist/src/over'; | ||
|
||
declare const number_object_lens: Lens<number, object>; | ||
declare const menual_lens_number_object: ManualLens<number, object>; | ||
declare const pseudo_lens_a: PseudoLens<'a'>; | ||
declare const pseudo_lens_1: PseudoLens<1>; | ||
|
||
declare const number_to_number: (x: number) => number; | ||
declare const object: object; | ||
declare const a_1_b_2_c_3: { a: 1; b: 2; c: 3 }; | ||
declare const number_array: number[]; | ||
declare const string_number_tuple: [string, number]; | ||
|
||
// @dts-jest:pass -> (target: object) => object | ||
R_over(number_object_lens, number_to_number); | ||
R_over(menual_lens_number_object, number_to_number); | ||
// @dts-jest:pass -> object | ||
R_over(number_object_lens)(number_to_number)(object); | ||
R_over(menual_lens_number_object)(number_to_number)(object); | ||
// @dts-jest:pass -> object | ||
R_over(number_object_lens, number_to_number, object); | ||
R_over(menual_lens_number_object, number_to_number, object); | ||
|
||
// @dts-jest:pass -> (target: Record<"a", any>) => Record<"a", any> | ||
R_over(pseudo_lens_a, number_to_number); | ||
// @dts-jest:pass -> Record<"a", any> | ||
R_over(pseudo_lens_a)(number_to_number)(a_1_b_2_c_3); | ||
// @dts-jest:pass -> { a: 1; b: 2; c: 3; } | ||
R_over(pseudo_lens_a, number_to_number, a_1_b_2_c_3); | ||
|
||
// @dts-jest:pass -> (target: {}) => {} | ||
R_over(pseudo_lens_1, number_to_number); | ||
// @dts-jest:pass -> {} | ||
R_over(pseudo_lens_1)(number_to_number)(string_number_tuple); | ||
// @dts-jest:pass -> [string, number] | ||
R_over(pseudo_lens_1, number_to_number, string_number_tuple); | ||
// @dts-jest:pass -> {} | ||
R_over(pseudo_lens_1)(number_to_number)(number_array); | ||
// @dts-jest:pass -> number[] | ||
R_over(pseudo_lens_1, number_to_number, number_array); |
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,13 +1,37 @@ | ||
import { Lens } from '../ramda/dist/src/$types'; | ||
import { ManualLens, PseudoLens } from '../ramda/dist/src/$types'; | ||
import * as R_set from '../ramda/dist/src/set'; | ||
|
||
declare const number_object_lens: Lens<number, object>; | ||
declare const number: number; | ||
declare const menual_lens_number_object: ManualLens<number, object>; | ||
declare const pseudo_lens_a: PseudoLens<'a'>; | ||
declare const pseudo_lens_1: PseudoLens<1>; | ||
|
||
declare const object: object; | ||
declare const a_1_b_2_c_3: { a: 1; b: 2; c: 3 }; | ||
declare const number_array: number[]; | ||
declare const string_number_tuple: [string, number]; | ||
declare const number: number; | ||
|
||
// @dts-jest:pass -> (target: object) => object | ||
R_set(number_object_lens, number); | ||
R_set(menual_lens_number_object, number); | ||
// @dts-jest:pass -> object | ||
R_set(number_object_lens)(number)(object); | ||
R_set(menual_lens_number_object)(number)(object); | ||
// @dts-jest:pass -> object | ||
R_set(number_object_lens, number, object); | ||
R_set(menual_lens_number_object, number, object); | ||
|
||
// @dts-jest:pass -> (target: Record<"a", any>) => Record<"a", any> | ||
R_set(pseudo_lens_a, number); | ||
// @dts-jest:pass -> Record<"a", any> | ||
R_set(pseudo_lens_a)(number)(a_1_b_2_c_3); | ||
// @dts-jest:pass -> { a: 1; b: 2; c: 3; } | ||
R_set(pseudo_lens_a, number, a_1_b_2_c_3); | ||
|
||
// @dts-jest:pass -> (target: {}) => {} | ||
R_set(pseudo_lens_1, number); | ||
// @dts-jest:pass -> {} | ||
R_set(pseudo_lens_1)(number)(string_number_tuple); | ||
// @dts-jest:pass -> [string, number] | ||
R_set(pseudo_lens_1, number, string_number_tuple); | ||
// @dts-jest:pass -> {} | ||
R_set(pseudo_lens_1)(number)(number_array); | ||
// @dts-jest:pass -> number[] | ||
R_set(pseudo_lens_1, number, number_array); |
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,12 +1,36 @@ | ||
import { Lens } from '../ramda/dist/src/$types'; | ||
import { ManualLens, PseudoLens } from '../ramda/dist/src/$types'; | ||
import * as R_view from '../ramda/dist/src/view'; | ||
|
||
declare const number_object_lens: Lens<number, object>; | ||
declare const menual_lens_number_object: ManualLens<number, object>; | ||
declare const pseudo_lens_a: PseudoLens<'a'>; | ||
declare const pseudo_lens_1: PseudoLens<1>; | ||
|
||
declare const object: object; | ||
declare const a_1_b_2_c_3: { a: 1; b: 2; c: 3 }; | ||
declare const number_array: number[]; | ||
declare const string_number_tuple: [string, number]; | ||
|
||
// @dts-jest:pass -> (target: object) => number | ||
R_view(number_object_lens); | ||
R_view(menual_lens_number_object); | ||
// @dts-jest:pass -> number | ||
R_view(number_object_lens)(object); | ||
R_view(menual_lens_number_object)(object); | ||
// @dts-jest:pass -> number | ||
R_view(number_object_lens, object); | ||
R_view(menual_lens_number_object, object); | ||
|
||
// @dts-jest:pass -> <U extends Record<"a", any>>(target: U) => U["a"] | ||
R_view(pseudo_lens_a); | ||
// @dts-jest:pass -> 1 | ||
R_view(pseudo_lens_a)(a_1_b_2_c_3); | ||
// @dts-jest:pass -> 1 | ||
R_view(pseudo_lens_a, a_1_b_2_c_3); | ||
|
||
// @dts-jest:pass -> <U extends { [index: number]: any; }>(target: U) => U["1"][1] | ||
R_view(pseudo_lens_1); | ||
// @dts-jest:pass -> any | ||
R_view(pseudo_lens_1)(string_number_tuple); | ||
// @dts-jest:pass -> any | ||
R_view(pseudo_lens_1, string_number_tuple); | ||
// @dts-jest:pass -> any | ||
R_view(pseudo_lens_1)(number_array); | ||
// @dts-jest:pass -> any | ||
R_view(pseudo_lens_1, number_array); |
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
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,6 @@ | ||
import { Lens } from './$types'; | ||
import { ManualLens } from './$types'; | ||
|
||
export function $<T, U>( | ||
getter: (target: U) => T, | ||
setter: (focus: T, target: U) => U, | ||
): Lens<T, U>; | ||
): ManualLens<T, U>; |
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,3 +1,3 @@ | ||
import { Lens, List } from './$types'; | ||
import { List, PseudoLens } from './$types'; | ||
|
||
export function $<T, U extends List<T>>(index: number): Lens<T, U>; | ||
export function $<N extends number>(index: N): PseudoLens<N>; |
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,3 +1,3 @@ | ||
import { Lens, Path } from './$types'; | ||
import { ManualLens, Path } from './$types'; | ||
|
||
export function $<T, U>(path: Path): Lens<T, U>; | ||
export function $<T, U>(path: Path): ManualLens<T, U>; |
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,3 +1,4 @@ | ||
import { Lens, Property } from './$types'; | ||
import { ManualLens, Property, PseudoLens } from './$types'; | ||
|
||
export function $<T, U>(property: Property): Lens<T, U>; | ||
export function $key<K extends string | number>(property: K): PseudoLens<K>; | ||
export function $general<T, U>(property: Property): ManualLens<T, U>; |
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,3 +1,23 @@ | ||
import { Lens, Morphism } from './$types'; | ||
import { NumberToString } from './$operation'; | ||
import { Dictionary, ManualLens, Morphism, PseudoLens } from './$types'; | ||
|
||
export function $<T, U>(lens: Lens<T, U>, fn: Morphism<T, T>, target: U): U; | ||
export function $number<N extends number, U extends { [index: number]: any }>( | ||
lens: PseudoLens<N>, | ||
fn: Morphism<U[NumberToString[N]], U[NumberToString[N]]>, | ||
target: U, | ||
): U; | ||
export function $string<K extends string, U extends Record<K, any>>( | ||
lens: PseudoLens<K>, | ||
fn: Morphism<U[K], U[K]>, | ||
target: U, | ||
): U; | ||
export function $manual<T, U>( | ||
lens: ManualLens<T, U>, | ||
fn: Morphism<T, T>, | ||
target: U, | ||
): U; | ||
export function $general<V, U>( | ||
lens: PseudoLens<any> | ManualLens<any, U>, | ||
fn: Morphism<V, V>, | ||
target: U, | ||
): U; |
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,3 +1,19 @@ | ||
import { Lens } from './$types'; | ||
import { NumberToString } from './$operation'; | ||
import { Dictionary, ManualLens, Morphism, PseudoLens } from './$types'; | ||
|
||
export function $<T, U>(lens: Lens<T, U>, value: T, target: U): U; | ||
export function $number<N extends number, U extends { [index: number]: any }>( | ||
lens: PseudoLens<N>, | ||
value: U[NumberToString[N]], | ||
target: U, | ||
): U; | ||
export function $string<K extends string, U extends Record<K, any>>( | ||
lens: PseudoLens<K>, | ||
value: U[K], | ||
target: U, | ||
): U; | ||
export function $manual<T, U>(lens: ManualLens<T, U>, value: T, target: U): U; | ||
export function $general<U>( | ||
lens: PseudoLens<any> | ManualLens<any, U>, | ||
fn: any, | ||
target: U, | ||
): U; |
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,3 +1,16 @@ | ||
import { Lens } from './$types'; | ||
import { NumberToString } from './$operation'; | ||
import { Dictionary, ManualLens, Morphism, PseudoLens } from './$types'; | ||
|
||
export function $<T, U>(lens: Lens<T, U>, target: U): T; | ||
export function $number<N extends number, U extends { [index: number]: any }>( | ||
lens: PseudoLens<N>, | ||
target: U, | ||
): U[NumberToString[N]]; | ||
export function $string<K extends string, U extends Record<K, any>>( | ||
lens: PseudoLens<K>, | ||
target: U, | ||
): U[K]; | ||
export function $manual<T, U>(lens: ManualLens<T, U>, target: U): T; | ||
export function $general<T, U>( | ||
lens: PseudoLens<any> | ManualLens<T, U>, | ||
target: U, | ||
): T | U[any]; |
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,7 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`R_lens(object_to_string) 1`] = `"(setter: (focus: string, target: object) => object) => Lens<string, object>"`; | ||
exports[`R_lens(object_to_string) 1`] = `"(setter: (focus: string, target: object) => object) => ManualLens<string, object>"`; | ||
|
||
exports[`R_lens(object_to_string)(string_object_to_object) 1`] = `"Lens<string, object>"`; | ||
exports[`R_lens(object_to_string)(string_object_to_object) 1`] = `"ManualLens<string, object>"`; | ||
|
||
exports[`R_lens(object_to_string, string_object_to_object) 1`] = `"Lens<string, object>"`; | ||
exports[`R_lens(object_to_string, string_object_to_object) 1`] = `"ManualLens<string, object>"`; |
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,5 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`R_lensIndex(0) 1`] = `"Lens<{}, {}[] | ArrayLike<{}>>"`; | ||
exports[`R_lensIndex(0) 1`] = `"PseudoLens<0>"`; | ||
|
||
exports[`R_lensIndex<number, number[]>(0) 1`] = `"Lens<number, number[]>"`; | ||
exports[`R_lensIndex(number) 1`] = `"PseudoLens<number>"`; |
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,5 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`R_lensPath(path) 1`] = `"Lens<{}, {}>"`; | ||
exports[`R_lensPath(path) 1`] = `"ManualLens<{}, {}>"`; | ||
|
||
exports[`R_lensPath<object, number[]>(path) 1`] = `"Lens<object, number[]>"`; | ||
exports[`R_lensPath<object, number[]>(path) 1`] = `"ManualLens<object, number[]>"`; |
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,5 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`R_lensProp(property) 1`] = `"Lens<{}, {}>"`; | ||
exports[`R_lensProp('x') 1`] = `"PseudoLens<\\"x\\">"`; | ||
|
||
exports[`R_lensProp<number, object>(property) 1`] = `"Lens<number, object>"`; | ||
exports[`R_lensProp(1) 1`] = `"PseudoLens<1>"`; | ||
|
||
exports[`R_lensProp(property) 1`] = `"ManualLens<{}, {}>"`; | ||
|
||
exports[`R_lensProp<number, object>(property) 1`] = `"ManualLens<number, object>"`; |
Oops, something went wrong.