Skip to content

Commit

Permalink
fix@issue #716
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Jan 16, 2024
1 parent 278bfec commit 6b66853
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 70 deletions.
47 changes: 36 additions & 11 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![Library size](https://img.shields.io/bundlephobia/minzip/rambda)
[![install size](https://packagephobia.com/badge?p=rambda)](https://packagephobia.com/result?p=rambda)
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/rambda)
[![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/selfrefactor/rambda/pulls)

## ❯ Example use

Expand Down Expand Up @@ -7925,6 +7926,19 @@ test('get (set(set s v1) v2) === v2', () => {

It returns a lens that focuses on specified `path`.

```javascript
const lensPath = R.lensPath(['x', 0, 'y'])
const input = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}

R.view(lensPath, input) // => 2

R.set(lensPath, 1, input)
// => {x: [{y: 1, z: 3}, {y: 4, z: 5}]}

R.over(xHeadYLens, R.negate, input)
// => {x: [{y: -2, z: 3}, {y: 4, z: 5}]}
```

<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20lensPath%20%3D%20R.lensPath(%5B'x'%2C%200%2C%20'y'%5D)%0Aconst%20input%20%3D%20%7Bx%3A%20%5B%7By%3A%202%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D%0A%0AR.view(lensPath%2C%20input)%20%2F%2F%20%3D%3E%202%0A%0AR.set(lensPath%2C%201%2C%20input)%20%0A%2F%2F%20%3D%3E%20%7Bx%3A%20%5B%7By%3A%201%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D%0A%0Aconst%20result%20%3D%20R.over(xHeadYLens%2C%20R.negate%2C%20input)%20%0A%2F%2F%20%3D%3E%20%7Bx%3A%20%5B%7By%3A%20-2%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D">Try this <strong>R.lensPath</strong> example in Rambda REPL</a>

[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#lensPath)
Expand Down Expand Up @@ -10489,7 +10503,8 @@ Logical OR

```typescript

over<T>(lens: Lens, fn: Arity1Fn, value: T): T
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S
```

It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
Expand All @@ -10507,12 +10522,12 @@ R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']) // => ['FOO', 'bar', 'baz']
<summary>All TypeScript definitions</summary>

```typescript
over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
over<T>(lens: Lens, fn: Arity1Fn, value: T[]): T[];
over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
over(lens: Lens, fn: Arity1Fn): <T>(value: T[]) => T[];
over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
over(lens: Lens): <T>(fn: Arity1Fn, value: T[]) => T[];
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S;
(fn: (a: A) => A, value: S): S;
};
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;
```

</details>
Expand Down Expand Up @@ -13999,7 +14014,10 @@ describe('R.reverse', () => {

```typescript

set<T, U>(lens: Lens, replacer: U, obj: T): T
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
}
```

It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
Expand All @@ -14022,9 +14040,12 @@ const result = [
<summary>All TypeScript definitions</summary>

```typescript
set<T, U>(lens: Lens, replacer: U, obj: T): T;
set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
};
set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;
```

</details>
Expand Down Expand Up @@ -18652,6 +18673,10 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.0.1

- Fix bad TS typings, due to missing declaration - [Issue #716](https://github.com/selfrefactor/rambda/issues/716)

9.0.0

Breaking change in TS definitions of `lenses` as now they are synced to `Ramda` types.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
9.0.1

- Fix bad TS typings, due to missing declaration - [Issue #716](https://github.com/selfrefactor/rambda/issues/716)

9.0.0

Breaking change in TS definitions of `lenses` as now they are synced to `Ramda` types.
Expand Down
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![Library size](https://img.shields.io/bundlephobia/minzip/rambda)
[![install size](https://packagephobia.com/badge?p=rambda)](https://packagephobia.com/result?p=rambda)
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/rambda)
[![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/selfrefactor/rambda/pulls)

## ❯ Example use

Expand Down Expand Up @@ -9802,7 +9803,8 @@ Logical OR

```typescript

over<T>(lens: Lens, fn: Arity1Fn, value: T): T
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S
```

It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
Expand All @@ -9814,12 +9816,12 @@ It returns a copied **Object** or **Array** with modified value received by appl
<summary>All TypeScript definitions</summary>

```typescript
over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
over<T>(lens: Lens, fn: Arity1Fn, value: T[]): T[];
over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
over(lens: Lens, fn: Arity1Fn): <T>(value: T[]) => T[];
over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
over(lens: Lens): <T>(fn: Arity1Fn, value: T[]) => T[];
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S;
(fn: (a: A) => A, value: S): S;
};
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;
```

</details>
Expand Down Expand Up @@ -13005,7 +13007,10 @@ describe('R.reverse', () => {

```typescript

set<T, U>(lens: Lens, replacer: U, obj: T): T
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
}
```

It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
Expand All @@ -13017,9 +13022,12 @@ It returns a copied **Object** or **Array** with modified `lens` focus set to `r
<summary>All TypeScript definitions</summary>

```typescript
set<T, U>(lens: Lens, replacer: U, obj: T): T;
set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
};
set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;
```

</details>
Expand Down Expand Up @@ -17242,6 +17250,10 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.0.1

- Fix bad TS typings, due to missing declaration - [Issue #716](https://github.com/selfrefactor/rambda/issues/716)

9.0.0

Breaking change in TS definitions of `lenses` as now they are synced to `Ramda` types.
Expand Down
34 changes: 23 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![Library size](https://img.shields.io/bundlephobia/minzip/rambda)
[![install size](https://packagephobia.com/badge?p=rambda)](https://packagephobia.com/result?p=rambda)
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/rambda)
[![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/selfrefactor/rambda/pulls)

## ❯ Example use

Expand Down Expand Up @@ -9802,7 +9803,8 @@ Logical OR

```typescript

over<T>(lens: Lens, fn: Arity1Fn, value: T): T
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S
```

It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
Expand All @@ -9814,12 +9816,12 @@ It returns a copied **Object** or **Array** with modified value received by appl
<summary>All TypeScript definitions</summary>

```typescript
over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
over<T>(lens: Lens, fn: Arity1Fn, value: T[]): T[];
over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
over(lens: Lens, fn: Arity1Fn): <T>(value: T[]) => T[];
over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
over(lens: Lens): <T>(fn: Arity1Fn, value: T[]) => T[];
over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S;
(fn: (a: A) => A, value: S): S;
};
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;
```

</details>
Expand Down Expand Up @@ -13005,7 +13007,10 @@ describe('R.reverse', () => {

```typescript

set<T, U>(lens: Lens, replacer: U, obj: T): T
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
}
```

It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
Expand All @@ -13017,9 +13022,12 @@ It returns a copied **Object** or **Array** with modified `lens` focus set to `r
<summary>All TypeScript definitions</summary>

```typescript
set<T, U>(lens: Lens, replacer: U, obj: T): T;
set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
};
set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;
```

</details>
Expand Down Expand Up @@ -17242,6 +17250,10 @@ describe('R.zipWith', () => {

## ❯ CHANGELOG

9.0.1

- Fix bad TS typings, due to missing declaration - [Issue #716](https://github.com/selfrefactor/rambda/issues/716)

9.0.0

Breaking change in TS definitions of `lenses` as now they are synced to `Ramda` types.
Expand Down
30 changes: 16 additions & 14 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface KeyValuePair<K, V> extends Array<K | V> {
0: K;
1: V;
}

export type Functor<A> = { map: <B>(fn: (a: A) => B) => Functor<B>; [key: string]: any };
export type Lens<S, A> = (functorFactory: (a: A) => Functor<A>) => (s: S) => Functor<S>;

type Arity1Fn = (x: any) => any;
Expand Down Expand Up @@ -2108,12 +2108,12 @@ Notes:
*/
// @SINGLE_MARKER
export function over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
export function over<T>(lens: Lens, fn: Arity1Fn, value: T[]): T[];
export function over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
export function over(lens: Lens, fn: Arity1Fn): <T>(value: T[]) => T[];
export function over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
export function over(lens: Lens): <T>(fn: Arity1Fn, value: T[]) => T[];
export function over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S;
(fn: (a: A) => A, value: S): S;
};
export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;

/*
Method: set
Expand All @@ -2139,9 +2139,12 @@ Notes:
*/
// @SINGLE_MARKER
export function set<T, U>(lens: Lens, replacer: U, obj: T): T;
export function set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
export function set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
export function set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
};
export function set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
export function set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;

/*
Method: view
Expand Down Expand Up @@ -7514,10 +7517,9 @@ Notes: Idea for this method comes from `ramda-adjunct` library
*/
// @SINGLE_MARKER
export function lensEq<T, U>(lens: Lens, target: T, input: U): boolean;
export function lensEq<T, U>(lens: Lens, target: T): (input: U) => boolean;
export function lensEq<T>(lens: Lens, target: T, input: T[]): boolean;
export function lensEq<T>(lens: Lens, target: T): (input: T[]) => boolean;
export function lensEq(lens: Function, value: any, data: any): boolean;
export function lensEq(lens: Function, value: any): (data: any) => boolean;
export function lensEq(lens: Function): (value: any) => (data: any) => boolean;

/*
Method: lensSatisfies
Expand Down
23 changes: 13 additions & 10 deletions immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface KeyValuePair<K, V> extends Array<K | V> {
readonly 0: K;
readonly 1: V;
}

export type Functor<A> = { readonly map: <B>(fn: (a: A) => B) => Functor<B>; readonly [key: string]: any };
export type Lens<S, A> = (functorFactory: (a: A) => Functor<A>) => (s: S) => Functor<S>;

type Arity1Fn = (x: any) => any;
Expand Down Expand Up @@ -1158,12 +1158,12 @@ export function or<T>(a: T): <U>(b: U) => T | U;
/**
* It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
*/
export function over<T>(lens: Lens, fn: Arity1Fn, value: T): T;
export function over<T>(lens: Lens, fn: Arity1Fn, value: readonly T[]): readonly T[];
export function over(lens: Lens, fn: Arity1Fn): <T>(value: T) => T;
export function over(lens: Lens, fn: Arity1Fn): <T>(value: readonly T[]) => readonly T[];
export function over(lens: Lens): <T>(fn: Arity1Fn, value: T) => T;
export function over(lens: Lens): <T>(fn: Arity1Fn, value: readonly T[]) => readonly T[];
export function over<S, A>(lens: Lens<S, A>): {
(fn: (a: A) => A): (value: S) => S;
(fn: (a: A) => A, value: S): S;
};
export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
export function over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;

/**
* It is very similar to `R.curry`, but you can pass initial arguments when you create the curried function.
Expand Down Expand Up @@ -1502,9 +1502,12 @@ export function reverse(input: string): string;
/**
* It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
*/
export function set<T, U>(lens: Lens, replacer: U, obj: T): T;
export function set<U>(lens: Lens, replacer: U): <T>(obj: T) => T;
export function set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
export function set<S, A>(lens: Lens<S, A>): {
(a: A): (obj: S) => S
(a: A, obj: S): S
};
export function set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
export function set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;

export function slice(from: number, to: number, input: string): string;
export function slice<T>(from: number, to: number, input: readonly T[]): readonly T[];
Expand Down
Loading

0 comments on commit 6b66853

Please sign in to comment.