Skip to content

Commit d5dcb10

Browse files
committed
Merged seq into index again
No point separating them right now, they're going to depend on each other. Also means I can remove the lodash dependency.
1 parent 3903919 commit d5dcb10

File tree

3 files changed

+52
-64
lines changed

3 files changed

+52
-64
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222
},
2323
"bugs": {
2424
"url": "https://github.com/Wolfy87/lazy-array/issues"
25-
},
26-
"dependencies": {
27-
"lodash": "^3.9.2"
2825
}
2926
}

src/index.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
var _ = require('lodash');
43
var LazyArray = require('./LazyArray');
5-
var seq = require('./seq');
64

75
/**
86
* Constructs a lazy array instance.
@@ -13,8 +11,57 @@ var seq = require('./seq');
1311
function create(fn) {
1412
return new LazyArray(fn);
1513
}
14+
/**
15+
* Get the first item in an array.
16+
*
17+
* @param {*[]} list
18+
* @return {*} First item.
19+
*/
20+
function first(list) {
21+
if (LazyArray.isLazyArray(list)) {
22+
return list.fn()[0];
23+
}
24+
else {
25+
return Array.isArray(list) ? list[0] : null;
26+
}
27+
}
28+
29+
/**
30+
* Get the tail of the array.
31+
*
32+
* @param {*[]} list
33+
* @return {*[]} Tail.
34+
*/
35+
function rest(list) {
36+
if (LazyArray.isLazyArray(list)) {
37+
return list.fn()[1];
38+
}
39+
else {
40+
return Array.isArray(list) ? list.slice(1) : [];
41+
}
42+
}
43+
44+
/**
45+
* Constructs a new array by prepending the item on the list. When given a
46+
* LazyArray instance to cons onto, it will return a value/LazyArray pair.
47+
*
48+
* @param {*} item
49+
* @param {*[]} list
50+
* @return {*[]} Original list with the item at the front.
51+
*/
52+
function cons(item, list) {
53+
if (LazyArray.isLazyArray(list)) {
54+
return [item, list];
55+
}
56+
else {
57+
return [item].concat(Array.isArray(list) ? list : []);
58+
}
59+
}
1660

17-
module.exports = _.assign({
61+
module.exports = {
1862
LazyArray: LazyArray,
19-
create: create
20-
}, seq);
63+
create: create,
64+
first: first,
65+
rest: rest,
66+
cons: cons
67+
};

src/seq.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)