Skip to content

Commit

Permalink
Merge c686db4 into 54d3f17
Browse files Browse the repository at this point in the history
  • Loading branch information
osorokotyaga committed Jan 31, 2019
2 parents 54d3f17 + c686db4 commit 9908dde
Show file tree
Hide file tree
Showing 143 changed files with 1,359 additions and 2,825 deletions.
21 changes: 0 additions & 21 deletions .babelrc

This file was deleted.

23 changes: 23 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
loose: true,
modules: false,
targets: {
chrome: 28,
safari: 6,
firefox: 28,
opera: 32,
ie: 11,
},
},
],
'@babel/preset-react',
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'babel-plugin-transform-es2015-modules-simple-commonjs',
],
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"curry",
"perfomance"
],
"sideEffects": false,
"license": "Apache-2.0",
"devDependencies": {
"@babel/cli": "^7.0.0",
Expand All @@ -31,6 +32,7 @@
"@types/jest": "^23.3.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"babel-plugin-transform-es2015-modules-simple-commonjs": "^0.3.0",
"benchmark": "^2.1.4",
"chalk": "^2.4.1",
"coveralls": "^3.0.1",
Expand Down
12 changes: 9 additions & 3 deletions src/array/adjust.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { adjust } from '../typings/types';
import curryN from '../function/curryN';
import concat from './concat';

interface Adjust {
<T>(fn: (a: T) => T, index: number, list: ReadonlyArray<T>): T[];
<T>(fn: (a: T) => T, index: number): (list: ReadonlyArray<T>) => T[];
<T>(fn: (a: T) => T): (index: number) => (list: ReadonlyArray<T>) => T[];
<T>(fn: (a: T) => T): (index: number, list: ReadonlyArray<T>) => T[];
}


/**
* Applies a function to the value at the given index of an array, returning a
* new copy of the array with the element at the given index replaced with the
Expand All @@ -20,7 +27,6 @@ import concat from './concat';
* adjust(add(10), 1, [1, 2, 3]); //=> [1, 12, 3]
* adjust(add(10))(1)([1, 2, 3]); //=> [1, 12, 3]
*/

export default curryN(3, (fn, idx, list) => {
if (idx >= list.length || idx < -list.length) {
return list;
Expand All @@ -32,4 +38,4 @@ export default curryN(3, (fn, idx, list) => {

result[index] = fn(list[index]);
return result;
}) as typeof adjust
}) as Adjust;
8 changes: 6 additions & 2 deletions src/array/all.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { all } from '../typings/types';
import curryN from '../function/curryN';

interface All {
<T>(fn: (a: T) => boolean, list: ReadonlyArray<T>): boolean;
<T>(fn: (a: T) => boolean): (list: ReadonlyArray<T>) => boolean;
}

/**
* Returns `true` if all the elements of the array match the predicate,
* `false` otherwise.
Expand All @@ -24,4 +28,4 @@ export default curryN(2, (fn, arr = []) => {
}

return true;
}) as typeof all
}) as All;
8 changes: 6 additions & 2 deletions src/array/any.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { any } from '../typings/types';
import curryN from '../function/curryN';

interface Any {
<T>(fn: (a: T) => boolean, list: ReadonlyArray<T>): boolean;
<T>(fn: (a: T) => boolean): (list: ReadonlyArray<T>) => boolean;
}

/**
* Returns `true` if at least one of elements of the list match the predicate,
* `false` otherwise.
Expand All @@ -24,4 +28,4 @@ export default curryN(2, (fn, arr = []) => {
}

return false;
}) as typeof any
}) as Any;
10 changes: 6 additions & 4 deletions src/array/append.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { append } from '../typings/types';
import concat from './concat';
import curryN from '../function/curryN';

interface Append {
<T>(el: T, list: ReadonlyArray<T>): T[];
<T>(el: T): <T>(list: ReadonlyArray<T>) => T[];
}

/**
* Returns a new list containing the contents of the given list, followed by
* the given element.
Expand All @@ -17,6 +21,4 @@ import curryN from '../function/curryN';
* append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
*/

export default curryN(2, (el, list) => (
concat(list, [el])
)) as typeof append
export default curryN(2, (el, list) => concat(list, [el])) as Append;
14 changes: 11 additions & 3 deletions src/array/concat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { concat } from '../typings/types';
import curryN from '../function/curryN';
import isArray from '../is/array';

interface Concat {
<T>(list1: ReadonlyArray<T>, list2: ReadonlyArray<T>): T[];
<T>(list1: ReadonlyArray<T>): (list2: ReadonlyArray<T>) => T[];
(list1: string, list2: string): string;
(list1: string): (list2: string) => string;
}

type Arg = Array<any> | string;

/**
* Returns the result of concatenating the given arrays or strings.
*
Expand All @@ -16,10 +24,10 @@ import isArray from '../is/array';
* concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
* concat([], []); //=> []
*/
export default curryN(2, (a = [], b = []) => {
export default curryN(2, (a: Arg = [], b: Arg = []) => {
if (isArray(a)) {
return a.concat(b);
}

return a + b;
}) as typeof concat
}) as Concat;
8 changes: 6 additions & 2 deletions src/array/difference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { difference } from '../typings/types';
import curryN from '../function/curryN';

interface Difference {
<T>(list1: ReadonlyArray<T>, list2: ReadonlyArray<T>): T[];
<T>(list1: ReadonlyArray<T>): (list2: ReadonlyArray<T>) => T[];
}

/**
* Returns the array of all elements in the first array not
* contained in the second array.
Expand All @@ -23,4 +27,4 @@ export default curryN(2, (a = [], b = []) => {
}

return result;
}) as typeof difference
}) as Difference;
15 changes: 12 additions & 3 deletions src/array/drop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { drop } from '../typings/types';
import slice from './slice';
import curryN from '../function/curryN';

interface Drop {
<T>(n: number, xs: ReadonlyArray<T>): T[];
(n: number, xs: string): string;
<T>(n: number): {
(xs: string): string;
(xs: ReadonlyArray<T>): T[];
};
}

/**
* Returns all but the first `n` elements of the given list, string.
*
Expand All @@ -15,6 +24,6 @@ import curryN from '../function/curryN';
* drop(4, ['foo', 'bar', 'baz']); //=> []
*/

export default curryN(2, (n, xs) => (
export default curryN(2, (n, xs) =>
slice(Math.max(0, n), Infinity, xs)
)) as typeof drop
) as Drop;
14 changes: 12 additions & 2 deletions src/array/dropLast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { dropLast } from '../typings/types';
import curryN from '../function/curryN';
import take from './take';

interface DropLast {
<T>(n: number, xs: ReadonlyArray<T>): T[];
(n: number, xs: string): string;
<T>(n: number): {
(xs: ReadonlyArray<T>): T[];
(xs: string): string;
};
}

/**
* Returns a list containing all but the last `n` elements of the given `list`.
*
Expand All @@ -16,4 +24,6 @@ import take from './take';
* dropLast(4, ['foo', 'bar', 'baz']); //=> []
* dropLast(3, 'ramda'); //=> 'ra'
*/
export default curryN(2, (n, xs) => take(n < xs.length ? xs.length - n : 0, xs)) as typeof dropLast
export default curryN(2, (n, xs) =>
take(n < xs.length ? xs.length - n : 0, xs)
) as DropLast;
8 changes: 6 additions & 2 deletions src/array/dropWhile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { dropWhile } from '../typings/types';
import curryN from '../function/curryN';

interface DropWhile {
<T>(fn: (a: T) => boolean, list: ReadonlyArray<T>): T[];
<T>(fn: (a: T) => boolean): (list: ReadonlyArray<T>) => T[];
}

/**
* Returns a new list excluding the leading elements of a given list which
* satisfy the supplied predicate function. It passes each value to the supplied
Expand All @@ -24,4 +28,4 @@ export default curryN(2, (fn, arr = []) => {
}

return arr.slice(idx);
}) as typeof dropWhile
}) as DropWhile;
20 changes: 14 additions & 6 deletions src/array/each.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import curryN from '../function/curryN';
import { each } from '../typings/types';

interface Each {
<TItem>(
fn: (item: TItem, index: number, arr: TItem[]) => void,
arr?: TItem[]
): void;
<TItem>(fn: (item: TItem, index: number, arr: TItem[]) => void): (
arr?: TItem[]
) => void;
}

/**
* Iterate over an input `list`, calling a provided function `fn` for each
Expand All @@ -16,8 +25,7 @@ import { each } from '../typings/types';
* // logs 8
*/
export default curryN(2, (fn, arr = []) => {
for (let i = 0; i < arr.length; i++) {
fn(arr[i], i, arr);
}
}) as typeof each

for (let i = 0; i < arr.length; i++) {
fn(arr[i], i, arr);
}
}) as Each;
13 changes: 11 additions & 2 deletions src/array/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import curryN from '../function/curryN';
import { filter } from '../typings/types';

interface Filter {
<TValue>(
fn: (value: TValue, i: number, arr: TValue[]) => any,
arr?: TValue[]
): TValue[];
<TValue>(fn: (value: TValue, i: number, arr: TValue[]) => any): (
arr?: TValue[]
) => TValue[];
}

/**
* Takes a predicate and a "arr", and returns a new array of the
Expand All @@ -25,4 +34,4 @@ export default curryN(2, (fn, arr = []) => {
}

return result;
}) as typeof filter
}) as Filter;
8 changes: 6 additions & 2 deletions src/array/find.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { find } from '../typings/types';
import curryN from '../function/curryN';

interface Find {
<T>(fn: (a: T) => boolean, list: ReadonlyArray<T>): T | undefined;
<T>(fn: (a: T) => boolean): (list: ReadonlyArray<T>) => T | undefined;
}

/**
* Returns the first element of the list which matches the predicate, or
* `undefined` if no element matches.
Expand All @@ -21,4 +25,4 @@ export default curryN(2, (fn, arr = []) => {
return arr[i];
}
}
}) as typeof find
}) as Find;
8 changes: 6 additions & 2 deletions src/array/findIndex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { findIndex } from '../typings/types';
import curryN from '../function/curryN';

interface FindIndex {
<T>(fn: (a: T) => boolean, list: ReadonlyArray<T>): number;
<T>(fn: (a: T) => boolean): (list: ReadonlyArray<T>) => number;
}

/**
* Returns the index of the first element of the list which matches the
* predicate, or `-1` if no element matches.
Expand All @@ -23,4 +27,4 @@ export default curryN(2, (fn, arr = []) => {
}

return -1;
}) as typeof findIndex
}) as FindIndex;
13 changes: 11 additions & 2 deletions src/array/findLast.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { findLast } from '../typings/types';
import curry from '../function/curry';

interface FindLast {
<T>(
fn: (a: T, index: number, list: ReadonlyArray<T>) => boolean,
list: ReadonlyArray<T>
): T | undefined;
<T>(fn: (a: T, index: number, list: ReadonlyArray<T>) => boolean): (
list: ReadonlyArray<T>
) => T | undefined;
}

/**
* Returns the last element of the list which matches the predicate, or
* `undefined` if no element matches.
Expand All @@ -22,4 +31,4 @@ export default curry((fn, list: ReadonlyArray<any>) => {
return list[i];
}
}
}) as typeof findLast;
}) as FindLast;
1 change: 1 addition & 0 deletions src/array/flatten.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isArrayLike from '../is/arrayLike';

/**
* Returns a new list by pulling every item out of it (and all its sub-arrays)
* and putting them in a new array, depth-first.
Expand Down
10 changes: 6 additions & 4 deletions src/array/head.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { head } from '../typings/types';
interface Head {
<T>(list: ReadonlyArray<T>): T | undefined;
(list: string): string;
}

/**
* Returns the first element of the given array.
*
Expand All @@ -9,6 +13,4 @@ import { head } from '../typings/types';
* head(['fi', 'fo', 'fum']); //=> 'fi'
* head([]); //=> undefined
*/
export default (
arr => arr && arr[0]
) as typeof head
export default ((arr) => arr && arr[0]) as Head;
Loading

0 comments on commit 9908dde

Please sign in to comment.