Skip to content

Commit

Permalink
Add Array.Empty (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
eubeez authored and jreina committed Oct 7, 2018
1 parent 5cc33c6 commit 15526e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ interface Array<T> {
Union<T>(adder: Array<T>): Array<T>;
Where<T>(predicate: (X: T) => boolean): Array<T>;
}

interface Array {
Empty(): Array<any>;
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const TakeWhile = require('./src/TakeWhile');
const ToDictionary = require('./src/ToDictionary');
const Union = require('./src/Union');
const Where = require('./src/Where');
const Empty = require('./src/Empty')

const bindAll = function() {
Array.prototype.Aggregate = Aggregate;
Array.prototype.All = All;
Array.prototype.Concat = Concat;
Array.prototype.Count = Count;
Array.prototype.ElementAt = ElementAt;
Array.Empty = Empty;
Array.prototype.First = First;
Array.prototype.Last = Last;
Array.prototype.Prepend = Prepend;
Expand All @@ -32,4 +34,4 @@ const bindAll = function() {
Array.prototype.Where = Where;
};

module.exports = bindAll;
module.exports = bindAll;
9 changes: 9 additions & 0 deletions src/Empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Returns an empty array
* @returns {Array}
*/
function Empty() {
return [];
}

module.exports = Empty;
12 changes: 12 additions & 0 deletions test/Empty.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const expect = require('chai').expect;
require('..')();

describe('Array#Empty', function() {

it('Should return an empty array', function() {
const expected = [];
const actual = Array.Empty();

expect(actual).to.eql(expected);
});
});

0 comments on commit 15526e5

Please sign in to comment.