Skip to content

Commit

Permalink
integrate iterarray dependency #8
Browse files Browse the repository at this point in the history
  • Loading branch information
xgbuils committed May 28, 2017
1 parent 01539c6 commit 9d0a862
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 36 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"arguments-verify": "^0.3.0",
"is-empty-iterable": "^1.0.0",
"iterarray": "^0.1.0",
"type-verify": "^0.4.0"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions src/fn/drop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IterArray = require('iterarray')

module.exports = function drop (iterable, n = 1) {
return this(IterArray(iterable).slice(n, Infinity))
}
6 changes: 3 additions & 3 deletions src/fn/includes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const findEntry = require('./findEntry')
const slice = require('../gen/slice')
const IterArray = require('iterarray')
const sameValueZero = require('../core/same-value-zero')

module.exports = function includes (iterable, e, fromIndex = 0) {
const sliceIterable = slice(iterable, fromIndex)
return !!findEntry(sliceIterable, value => sameValueZero(value, e))
const slicedIterable = IterArray(iterable).slice(fromIndex, Infinity)
return !!findEntry(slicedIterable, value => sameValueZero(value, e))
}
6 changes: 3 additions & 3 deletions src/fn/indexOf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const findIndex = require('./findIndex')
const slice = require('../gen/slice')
const IterArray = require('iterarray')

module.exports = function indexOf (iterable, e, fromIndex = 0) {
const sliceIterable = slice(iterable, fromIndex)
const index = findIndex(sliceIterable, value => value === e)
const slicedIterable = IterArray(iterable).slice(fromIndex, Infinity)
const index = findIndex(slicedIterable, value => value === e)
return index === -1 ? -1 : fromIndex + index
}
5 changes: 5 additions & 0 deletions src/fn/slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IterArray = require('iterarray')

module.exports = function slice (iterable, start = 0, end = Infinity) {
return IterArray(iterable).slice(start, end)
}
5 changes: 5 additions & 0 deletions src/fn/take.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IterArray = require('iterarray')

module.exports = function take (iterable, n = 1) {
return this(IterArray(iterable).slice(0, n))
}
5 changes: 0 additions & 5 deletions src/gen/drop.js

This file was deleted.

18 changes: 4 additions & 14 deletions src/gen/slice.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module.exports = function* slice (iterable, start = 0, end = Infinity) {
if (start >= end) {
return
}
let index
const iterator = iterable[Symbol.iterator]()
for (index = 0; index < end; ++index) {
const state = iterator.next()
if (state.done) {
return
} else if (index >= start) {
yield state.value
}
}
const IterArray = require('iterarray')

module.exports = function slice (iterable, start = 0, end = Infinity) {
return this(IterArray(iterable).slice(start, end))
}
5 changes: 0 additions & 5 deletions src/gen/take.js

This file was deleted.

12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const factory = require('./factory')
const Iterable = require('./core/iterable')

const concat = require('./gen/concat')
const drop = require('./gen/drop')
const dropWhile = require('./gen/dropWhile')
const entries = require('./gen/entries')
const filter = require('./gen/filter')
Expand All @@ -14,14 +13,13 @@ const permutations = require('./gen/permutations')
const product = require('./gen/product')
const range = require('./gen/range')
const repeat = require('./gen/repeat')
const slice = require('./gen/slice')
const take = require('./gen/take')
const takeWhile = require('./gen/takeWhile')
const uniq = require('./gen/uniq')
const uniqBy = require('./gen/uniqBy')
const uniqWith = require('./gen/uniqWith')
const zip = require('./gen/zip')

const drop = require('./fn/drop')
const every = require('./fn/every')
const find = require('./fn/find')
const findEntry = require('./fn/findEntry')
Expand All @@ -35,7 +33,9 @@ const isEqualBy = require('./fn/isEqualBy')
const isEqualWith = require('./fn/isEqualWith')
const reduce = require('./fn/reduce')
const reduceRight = require('./fn/reduceRight')
const slice = require('./fn/slice')
const some = require('./fn/some')
const take = require('./fn/take')

const optionalNumber = ['Number', 'Undefined']
const infiniteIterablesValidation = [[], [Iterable], Infinity]
Expand All @@ -55,7 +55,7 @@ const Iterum = factory({
validation: infiniteIterablesValidation
},
drop: {
gen: drop,
fn: drop,
validation: optionalNumberValidation
},
dropWhile: {
Expand Down Expand Up @@ -143,15 +143,15 @@ const Iterum = factory({
validation: optionalNumberValidation
},
slice: {
gen: slice,
fn: slice,
validation: [[], optionalNumber, optionalNumber]
},
some: {
fn: some,
validation: functionValidation
},
take: {
gen: take,
fn: take,
validation: optionalNumberValidation
},
takeWhile: {
Expand Down

0 comments on commit 9d0a862

Please sign in to comment.