Skip to content

Commit

Permalink
Merge pull request #3 from emonkak/2.0
Browse files Browse the repository at this point in the history
Version 2.0
  • Loading branch information
emonkak committed Feb 24, 2017
2 parents 5c0d67e + 2cc3077 commit e882541
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 18 deletions.
3 changes: 1 addition & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@emonkak/enumerable",
"version": "1.1.0",
"version": "2.0.0",
"description": "Provides the individual methods of LINQ as a module",
"main": "index.js",
"scripts": {
Expand All @@ -9,7 +9,6 @@
"lint": "tslint 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rm -f -r dist",
"precover": "rm -f -r .nyc_output coverage",
"prepublish": "npm run build",
"test": "mocha --recursive --compilers ts:ts-node/register",
"watch": "tsc --watch"
},
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/maxBy.ts
@@ -1,14 +1,14 @@
import maxByFn from '../maxBy';
import { Enumerable } from '../internal/Enumerable';

function maxBy<TSource, TKey>(this: Enumerable<TSource>, keySelector: (element: TSource) => TKey): TSource[] {
return maxByFn.call(this.source, keySelector);
function maxBy<TSource, TKey>(this: Enumerable<TSource>, keySelector: (element: TSource) => TKey): Enumerable<TSource> {
return this.lift<TSource>(maxByFn.call(this.source, keySelector));
}

Enumerable.prototype.maxBy = maxBy;

declare module '../internal/Enumerable' {
interface Enumerable<TSource> {
maxBy<TKey>(keySelector: (element: TSource) => TKey): TSource[];
maxBy<TKey>(keySelector: (element: TSource) => TKey): Enumerable<TSource>;
}
}
6 changes: 3 additions & 3 deletions src/extensions/minBy.ts
@@ -1,14 +1,14 @@
import minByFn from '../minBy';
import { Enumerable } from '../internal/Enumerable';

function minBy<TSource, TKey>(this: Enumerable<TSource>, keySelector: (element: TSource) => TKey): TSource[] {
return minByFn.call(this.source, keySelector);
function minBy<TSource, TKey>(this: Enumerable<TSource>, keySelector: (element: TSource) => TKey): Enumerable<TSource> {
return this.lift<TSource>(minByFn.call(this.source, keySelector));
}

Enumerable.prototype.minBy = minBy;

declare module '../internal/Enumerable' {
interface Enumerable<TSource> {
minBy<TKey>(keySelector: (element: TSource) => TKey): TSource[];
minBy<TKey>(keySelector: (element: TSource) => TKey): Enumerable<TSource>;
}
}
6 changes: 1 addition & 5 deletions src/static/repeat.ts
Expand Up @@ -2,7 +2,7 @@ import EmptyPartition from '../internal/EmptyPartition';
import { argumentOutOfRange } from '../internal/errors';
import RepeatPartition from '../internal/RepeatPartition';

export default function repeat<TSource>(element: TSource, count?: number): Iterable<TSource> {
export default function repeat<TSource>(element: TSource, count: number = Infinity): Iterable<TSource> {
if (count < 0) {
throw argumentOutOfRange('count');
}
Expand All @@ -11,9 +11,5 @@ export default function repeat<TSource>(element: TSource, count?: number): Itera
return new EmptyPartition<TSource>();
}

if (count == null) {
count = Infinity;
}

return new RepeatPartition(element, count);
}
2 changes: 1 addition & 1 deletion src/toArray.ts
@@ -1,3 +1,3 @@
export default function toArray<TSource>(this: Iterable<TSource>): TSource[] {
return Array.from(this);
return Array.isArray(this) ? this as TSource[] : Array.from(this);
}
4 changes: 2 additions & 2 deletions test/maxByTest.ts
Expand Up @@ -3,7 +3,7 @@ import Enumerable from './bundle';

describe('maxBy()', () => {
it('should returns the elements with the minimum key value by using the default comparer to compare key values', () => {
assert.deepEqual(new Enumerable([3, 2, 1, 2, 3]).maxBy(x => x), [3, 3]);
assert.deepEqual(new Enumerable(['ab', 'abc', 'ab', 'a', 'ab', 'abc', 'ab']).maxBy(s => s.length), ['abc', 'abc']);
assert.deepEqual(new Enumerable([3, 2, 1, 2, 3]).maxBy(x => x).toArray(), [3, 3]);
assert.deepEqual(new Enumerable(['ab', 'abc', 'ab', 'a', 'ab', 'abc', 'ab']).maxBy(s => s.length).toArray(), ['abc', 'abc']);
});
});
4 changes: 2 additions & 2 deletions test/minByTest.ts
Expand Up @@ -3,7 +3,7 @@ import Enumerable from './bundle';

describe('minBy()', () => {
it('should returns the elements with the maximum key value by using the default comparer to compare key values', () => {
assert.deepEqual(new Enumerable([1, 2, 3, 2, 1]).minBy(x => x), [1, 1]);
assert.deepEqual(new Enumerable(['ab', 'a', 'ab', 'abc', 'ab', 'a', 'ab']).minBy(s => s.length), ['a', 'a']);
assert.deepEqual(new Enumerable([1, 2, 3, 2, 1]).minBy(x => x).toArray(), [1, 1]);
assert.deepEqual(new Enumerable(['ab', 'a', 'ab', 'abc', 'ab', 'a', 'ab']).minBy(s => s.length).toArray(), ['a', 'a']);
});
});

0 comments on commit e882541

Please sign in to comment.