Comparing version 0.0.12 to 0.0.13
@@ -1,4 +0,4 @@ | ||
function Forward (array) { | ||
function Forward (array, index) { | ||
this._array = array | ||
this._index = 0 | ||
this._index = index == null ? 0 : index | ||
} | ||
@@ -22,9 +22,9 @@ | ||
exports.forward = function (array) { | ||
return new Forward(array) | ||
exports.forward = function (array, index) { | ||
return new Forward(array, index) | ||
} | ||
function Reverse (array) { | ||
function Reverse (array, index) { | ||
this._array = array | ||
this._index = array.length - 1 | ||
this._index = index == null ? array.length - 1 : index | ||
} | ||
@@ -48,4 +48,4 @@ | ||
exports.reverse = function (array) { | ||
return new Reverse(array) | ||
exports.reverse = function (array, index) { | ||
return new Reverse(array, index) | ||
} |
{ | ||
"name": "advance", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"author": "Alan Gutierrez <alan@prettyrobots.com>", | ||
@@ -5,0 +5,0 @@ "description": "In-memory forward iterator for use with the Strata b-tree MVCC tool collection.", |
@@ -1,7 +0,9 @@ | ||
require('proof')(3, require('cadence/redux')(prove)) | ||
require('proof')(6, require('cadence/redux')(prove)) | ||
function prove (async, assert) { | ||
var values = [ 'a', 'b', 'c' ] | ||
var iterator = require('../..').forward(values) | ||
var advance = require('../..') | ||
var iterator | ||
async(function () { | ||
iterator = advance.forward(values) | ||
iterator.next(async()) | ||
@@ -20,3 +22,18 @@ }, function (more) { | ||
iterator.unlock(async()) | ||
}, function () { | ||
iterator = advance.forward(values, 1) | ||
iterator.next(async()) | ||
}, function (more) { | ||
assert(more, 'more') | ||
var items = [], item | ||
while (item = iterator.get()) { | ||
items.push(item) | ||
} | ||
assert(items, [ 'b', 'c' ], 'next with index') | ||
iterator.next(async()) | ||
}, function (more) { | ||
assert(!more, 'no more with index') | ||
}, function () { | ||
iterator.unlock(async()) | ||
}) | ||
} |
@@ -1,7 +0,9 @@ | ||
require('proof')(3, require('cadence/redux')(prove)) | ||
require('proof')(6, require('cadence/redux')(prove)) | ||
function prove (async, assert) { | ||
var values = [ 'a', 'b', 'c' ] | ||
var iterator = require('../..').reverse(values) | ||
var advance = require('../..') | ||
var iterator | ||
async(function () { | ||
iterator = advance.reverse(values) | ||
iterator.next(async()) | ||
@@ -20,3 +22,18 @@ }, function (more) { | ||
iterator.unlock(async()) | ||
}, function () { | ||
iterator = advance.reverse(values, 1) | ||
iterator.next(async()) | ||
}, function (more) { | ||
assert(more, 'more') | ||
var items = [], item | ||
while (item = iterator.get()) { | ||
items.push(item) | ||
} | ||
assert(items, [ 'b', 'a' ], 'next with index') | ||
iterator.next(async()) | ||
}, function (more) { | ||
assert(!more, 'no more with index') | ||
}, function () { | ||
iterator.unlock(async()) | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8233
114