Skip to content

Commit

Permalink
Allow 'adjust' to accept read only input array (#3671)
Browse files Browse the repository at this point in the history
* make adjust to work with read only input array

* Add missed import

* Add missing definition for flow prior to 0.104
  • Loading branch information
quanlinc authored and AndrewSouthpaw committed Jan 6, 2020
1 parent 4618dce commit c339c49
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
18 changes: 9 additions & 9 deletions definitions/npm/ramda_v0.26.x/flow_v0.104.x-/ramda_v0.26.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,18 +616,18 @@ declare module ramda {
x === null);

// *List
declare function adjust<T>(
declare function adjust<A>(
index: number,
): (fn: (a: T) => T) => (src: Array<T>) => Array<T>;
declare function adjust<T>(
): (fn: (a: A) => A) => (src: $ReadOnlyArray<A>) => Array<A>;
declare function adjust<A>(
index: number,
fn: (a: T) => T,
): (src: Array<T>) => Array<T>;
declare function adjust<T>(
fn: (a: A) => A,
): (src: $ReadOnlyArray<A>) => Array<A>;
declare function adjust<A>(
index: number,
fn: (a: T) => T,
src: Array<T>
): Array<T>;
fn: (a: A) => A,
src: $ReadOnlyArray<A>
): Array<A>;

declare function all<T>(fn: UnaryPredicateFn<T>, xs: Array<T>): boolean;
declare function all<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*eslint-disable no-undef, no-unused-vars, no-console*/
import _, {
type RefineFilter,
adjust,
append,
compose,
concat,
Expand Down Expand Up @@ -824,6 +825,17 @@ const str: string = "hello world";
y: b
}))([1, 2, 3])(["1", "2", "3"]);

describe('adjust', () => {
it('should allow both Array and $ReadOnlyArray output', () => {
const arr: Array<number> = [1, 2, 3]
const ro: $ReadOnlyArray<number> = [1, 2, 3]
const result: $ReadOnlyArray<number> = adjust(1, x => x + 1, arr)
const result1: Array<number> = adjust(1, x => x + 1, arr)
const result2: $ReadOnlyArray<number> = adjust(1, x => x + 1, ro)
const result3: Array<number> = adjust(1, x => x + 1, ro)
});
});

describe('uniq', () => {
it('should accept read only array', () => {
const readOnlyNumbers: $ReadOnlyArray<number> = [1,1,2,3,4,3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,18 +581,18 @@ declare module ramda {
x === null);

// *List
declare function adjust<T>(
declare function adjust<A>(
index: number,
): (fn: (a: T) => T) => (src: Array<T>) => Array<T>;
declare function adjust<T>(
): (fn: (a: A) => A) => (src: $ReadOnlyArray<A>) => Array<A>;
declare function adjust<A>(
index: number,
fn: (a: T) => T,
): (src: Array<T>) => Array<T>;
declare function adjust<T>(
fn: (a: A) => A,
): (src: $ReadOnlyArray<A>) => Array<A>;
declare function adjust<A>(
index: number,
fn: (a: T) => T,
src: Array<T>
): Array<T>;
fn: (a: A) => A,
src: $ReadOnlyArray<A>
): Array<A>;

declare function all<T>(fn: UnaryPredicateFn<T>, xs: Array<T>): boolean;
declare function all<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*eslint-disable no-undef, no-unused-vars, no-console*/
import _, {
type RefineFilter,
adjust,
append,
compose,
concat,
Expand Down Expand Up @@ -704,6 +705,17 @@ const str: string = "hello world";
y: b
}))([1, 2, 3])(["1", "2", "3"]);

describe('adjust', () => {
it('should allow both Array and $ReadOnlyArray output', () => {
const arr: Array<number> = [1, 2, 3]
const ro: $ReadOnlyArray<number> = [1, 2, 3]
const result: $ReadOnlyArray<number> = adjust(1, x => x + 1, arr)
const result1: Array<number> = adjust(1, x => x + 1, arr)
const result2: $ReadOnlyArray<number> = adjust(1, x => x + 1, ro)
const result3: Array<number> = adjust(1, x => x + 1, ro)
});
});

describe('uniq', () => {
it('should accept read only array', () => {
const readOnlyNumbers: $ReadOnlyArray<number> = [1,1,2,3,4,3];
Expand Down

0 comments on commit c339c49

Please sign in to comment.