Skip to content

Commit

Permalink
fix@issue #714 sync types
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Jan 4, 2024
1 parent 180d9f2 commit b295779
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 170 deletions.
16 changes: 14 additions & 2 deletions NEXT_VERSION_CHECKLIST.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
sync lenses types with ramda

- innerJoin
- gt
- gte
- reduceBy
- hasIn

go to source definition in vscode works better for ramda than for rambda

---
test for which cases - ts, js
---
such types as `SortObjectPredicate` need to be exported
---
in js project like niketa theme, go to source lead to readable code, is ramda the same?

Expand All @@ -26,6 +34,12 @@ such as

sortObject
---
R.findInObject
---
restore maptoobject x@2.1.0

why mapObject is not same
---
REFS:

- forEachObjIndexed should not contain source file nor test file
Expand All @@ -50,7 +64,6 @@ group TS test for similar methods
- constructN


- innerJoin
- insert
- insertAll
- into
Expand Down Expand Up @@ -84,7 +97,6 @@ group TS test for similar methods
- project
- promap

- reduceBy
- reduceRight
- reduceWhile
- reduced
Expand Down
71 changes: 52 additions & 19 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ interface KeyValuePair<K, V> extends Array<K | V> {
1: V;
}

export interface Lens {
<T, U>(obj: T): U;
set<T, U>(str: string, obj: T): U;
}
export type Lens<S, A> = (functorFactory: (a: A) => Functor<A>) => (s: S) => Functor<S>;

type Arity1Fn = (x: any) => any;
type Arity2Fn = (x: any, y: any) => any;
Expand Down Expand Up @@ -147,12 +144,12 @@ interface SchemaAsync {
[key: string]: Promise<boolean>;
}

interface IsValid {
export interface IsValid {
input: object;
schema: Schema;
}

interface IsValidAsync {
export interface IsValidAsync {
input: object;
schema: Schema | SchemaAsync;
}
Expand All @@ -174,8 +171,6 @@ type ApplyDiffAdd = {op:'add', path: string, value: any};
type ApplyDiffRemove = {op:'remove', path: string};
type ApplyDiffRule = ApplyDiffUpdate | ApplyDiffAdd | ApplyDiffRemove;

type Resolved<T> = {status: 'fulfilled', value: T} | {status: 'rejected', reason: string|Error}

// API_MARKER

/*
Expand Down Expand Up @@ -1977,7 +1972,7 @@ Notes:
*/
// @SINGLE_MARKER
export function lens<T, U, V>(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens;
export function lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>;

/*
Method: lensIndex
Expand All @@ -2001,7 +1996,8 @@ Notes:
*/
// @SINGLE_MARKER
export function lensIndex(index: number): Lens;
export function lensIndex<A>(n: number): Lens<A[], A>;
export function lensIndex<A extends any[], N extends number>(n: N): Lens<A, A[N]>;

/*
Method: lensPath
Expand Down Expand Up @@ -2029,8 +2025,41 @@ Notes:
*/
// @SINGLE_MARKER
export function lensPath(path: RamdaPath): Lens;
export function lensPath(path: string): Lens;
export function lensPath<S, K0 extends keyof S = keyof S>(path: [K0]): Lens<S, S[K0]>;
export function lensPath<S, K0 extends keyof S = keyof S, K1 extends keyof S[K0] = keyof S[K0]>(
path: [K0, K1],
): Lens<S, S[K0][K1]>;
export function lensPath<
S,
K0 extends keyof S = keyof S,
K1 extends keyof S[K0] = keyof S[K0],
K2 extends keyof S[K0][K1] = keyof S[K0][K1]
>(path: [K0, K1, K2]): Lens<S, S[K0][K1][K2]>;
export function lensPath<
S,
K0 extends keyof S = keyof S,
K1 extends keyof S[K0] = keyof S[K0],
K2 extends keyof S[K0][K1] = keyof S[K0][K1],
K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2]
>(path: [K0, K1, K2, K3]): Lens<S, S[K0][K1][K2][K3]>;
export function lensPath<
S,
K0 extends keyof S = keyof S,
K1 extends keyof S[K0] = keyof S[K0],
K2 extends keyof S[K0][K1] = keyof S[K0][K1],
K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3]
>(path: [K0, K1, K2, K3, K4]): Lens<S, S[K0][K1][K2][K3][K4]>;
export function lensPath<
S,
K0 extends keyof S = keyof S,
K1 extends keyof S[K0] = keyof S[K0],
K2 extends keyof S[K0][K1] = keyof S[K0][K1],
K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
K5 extends keyof S[K0][K1][K2][K3][K4] = keyof S[K0][K1][K2][K3][K4]
>(path: [K0, K1, K2, K3, K4, K5]): Lens<S, S[K0][K1][K2][K3][K4][K5]>;
export function lensPath<S = any, A = any>(path: Path): Lens<S, A>;

/*
Method: lensProp
Expand Down Expand Up @@ -2058,10 +2087,7 @@ Notes:
*/
// @SINGLE_MARKER
export function lensProp(prop: string): {
<T, U>(obj: T): U;
set<T, U, V>(val: T, obj: U): V;
};
export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;

/*
Method: over
Expand Down Expand Up @@ -2137,8 +2163,8 @@ Notes:
*/
// @SINGLE_MARKER
export function view<T, U>(lens: Lens): (target: T) => U;
export function view<T, U>(lens: Lens, target: T): U;
export function view<S, A>(lens: Lens<S, A>): (obj: S) => A;
export function view<S, A>(lens: Lens<S, A>, obj: S): A;

/*
Method: map
Expand Down Expand Up @@ -5822,7 +5848,14 @@ Notes:
*/
// @SINGLE_MARKER
export function innerJoin<T>(x: T): T;
export function innerJoin<T1, T2>(
pred: (a: T1, b: T2) => boolean,
): (list1: T1[], list2: T2[]) => T1[];
export function innerJoin<T1, T2>(
pred: (a: T1, b: T2) => boolean,
list1: T1[],
): (list2: T2[]) => T1[];
export function innerJoin<T1, T2>(pred: (a: T1, b: T2) => boolean, list1: T1[], list2: T2[]): T1[];

// RAMBDAX_MARKER_START

Expand Down
59 changes: 25 additions & 34 deletions source/hasIn.spec.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
import { hasIn } from './hasIn'
import { hasIn as hasInRamda } from 'ramda'

test('happy', () => {
const result = hasIn()
console.log(result)
})

/*
var R = require('../source/index.js')
var eq = require('./shared/eq.js')
describe('hasIn', function () {
var fred = {name: 'Fred', age: 23}
var anon = {age: 99}
import { hasIn } from './hasIn.js'

it('returns a function that checks the appropriate property', function () {
var nm = R.hasIn('name')
eq(typeof nm, 'function')
eq(nm(fred), true)
eq(nm(anon), false)
})
const fred = {
age : 23,
name : 'Fred',
}
const anon = { age : 99 }

it('checks properties from the prototype chain', function () {
var Person = function () {}
Person.prototype.age = function () {}
test('returns a function that checks the appropriate property', () => {
const nm = hasIn('name')
expect(typeof nm).toBe('function')
expect(nm(fred)).toBe(true)
expect(nm(anon)).toBe(false)
})

var bob = new Person()
eq(R.hasIn('age', bob), true)
})
test('checks properties from the prototype chain', () => {
function Person(){}
Person.prototype.age = function (){}

it('works properly when called with two arguments', function () {
eq(R.hasIn('name', fred), true)
eq(R.hasIn('name', anon), false)
})
const bob = new Person()
expect(hasIn('age', bob)).toBe(true)
})

it('returns false when non-existent object', function () {
eq(R.hasIn('name', null), false)
eq(R.hasIn('name', undefined), false)
})
test('works properly when called with two arguments', () => {
expect(hasIn('name', fred)).toBe(true)
expect(hasIn('name', anon)).toBe(false)
})

*/
test('returns false when non-existent object', () => {
expect(hasIn('name', null)).toBe(false)
expect(hasIn('name', undefined)).toBe(false)
})
51 changes: 23 additions & 28 deletions source/innerJoin.spec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import { innerJoin } from './innerJoin'
import { innerJoin as innerJoinRamda } from 'ramda'

test('happy', () => {
const result = innerJoin()
console.log(result)
})
import { innerJoin } from './innerJoin.js'

/*
var R = require('../source/index.js')
var eq = require('./shared/eq.js')
const a = {
id : 1,
name : 'a',
}
const b = {
id : 2,
name : 'b',
}
const c = {
id : 3,
name : 'c',
}
const f = innerJoin((r, id) => r.id === id)

var a = {id: 1, name: 'a'}
var b = {id: 2, name: 'b'}
var c = {id: 3, name: 'c'}
var f = R.innerJoin(function (r, id) {
return r.id === id
test('only returns elements from the first list', () => {
expect(f([ a, b, c ], [])).toEqual([])
expect(f([ a, b, c ], [ 1 ])).toEqual([ a ])
expect(f([ a, b, c ], [ 1, 2 ])).toEqual([ a, b ])
expect(f([ a, b, c ], [ 1, 2, 3 ])).toEqual([ a, b, c ])
expect(f([ a, b, c ], [ 1, 2, 3, 4 ])).toEqual([ a, b, c ])
})

describe('innerJoin', function () {
it('only returns elements from the first list', function () {
eq(f([a, b, c], []), [])
eq(f([a, b, c], [1]), [a])
eq(f([a, b, c], [1, 2]), [a, b])
eq(f([a, b, c], [1, 2, 3]), [a, b, c])
eq(f([a, b, c], [1, 2, 3, 4]), [a, b, c])
})
it('does not remove duplicates', function () {
eq(f([a, a, a], [1, 2, 3]), [a, a, a])
eq(f([a, b, c], [1, 1, 1]), [a])
})
test('does not remove duplicates', () => {
expect(f([ a, a, a ], [ 1, 2, 3 ])).toEqual([ a, a, a ])
expect(f([ a, b, c ], [ 1, 1, 1 ])).toEqual([ a ])
})
*/
43 changes: 40 additions & 3 deletions source/lens-spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
import {lens, assoc} from 'rambda'
import {lens, assoc, lensProp, view, lensIndex, lensPath} from 'rambda'

interface Input {
foo: string,
}
const testObject: Input = {
foo: 'Jazz',
}

describe('R.lens', () => {
it('happy', () => {
const fn = lens<Input, string, string>((x: Input) => {
const fn = lens<Input, string>((x: Input) => {
x.foo // $ExpectType string
return x.foo
}, assoc('name'))
fn // $ExpectType Lens
fn // $ExpectType Lens<Input, string>
})
})

describe('R.lensProp', () => {
it('happy', () => {
const result = view<Input, string>(lensProp('foo'), testObject)
result // $ExpectType string
})
})

describe('R.lensIndex', () => {
const testList: Input[] = [{foo: 'bar'}, {foo: 'baz'}]
it('happy', () => {
const result = view<Input[], Input>(lensIndex(0), testList)
result // $ExpectType Input
result.foo // $ExpectType string
})
})

describe('R.lensPath', () => {
const path = lensPath(['bar', 'a'])
it('happy', () => {
const result = view<Input, string>(path, testObject)
result // $ExpectType string
})
})

describe('R.view', () => {
const fooLens = lens<Input, string>((x: Input) => {
return x.foo
}, assoc('foo'))
it('happt', () => {
const result = view<Input, string>(fooLens, testObject)
result // $ExpectType string
})
})
14 changes: 0 additions & 14 deletions source/lensIndex-spec.ts

This file was deleted.

Loading

0 comments on commit b295779

Please sign in to comment.