diff --git a/.travis.yml b/.travis.yml index 3a774c8..181c8c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,10 @@ language: node_js node_js: - - 9 + - 10 cache: yarn branches: except: - /^no-ci.*$/ script: - - yarn test - yarn test-coveralls - yarn typecheck diff --git a/package.json b/package.json index 2a15c32..f11b7de 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "./scripts/build.sh", "typecheck": "tsc --noEmit", "test": "TIMEOUT=2000 jest --env=node", - "test-coveralls": "TIMEOUT=2000 jest --env=node --coverage --coverageReporters=text-lcov | coveralls" + "test-coveralls": "TIMEOUT=2000 jest --env=node --coverage --coverageReporters=text-lcov --forceExit | coveralls" }, "dependencies": { "@ericandrewlewis/bitmap": "^1.0.0", diff --git a/src/list.js b/src/list.js index c53aa46..0d055da 100644 --- a/src/list.js +++ b/src/list.js @@ -373,6 +373,24 @@ function set_tail(xs,x) { } } +// take(xs, n) puts the first n elements of xs into a list. +function take(xs, n) { + if (n < 0) { + throw new Error("take(xs, n) expects a positive integer as " + + "argument n, but encountered " + n); + } + return (n === 0) ? [] : pair(head(xs), take(tail(xs), n - 1)); +} + +// drop(xs, n) removes the first n elements from xs and returns the rest (as a list) +function drop(xs, n) { + if (n < 0) { + throw new Error("drop(xs, n) expects a positive integer as " + + "argument n, but encountered " + n); + } + return (n === 0) ? xs : drop(tail(xs), n - 1); +} + global.array_test = array_test; global.pair = pair; global.is_pair = is_pair; @@ -399,3 +417,5 @@ global.list_ref = list_ref; global.accumulate = accumulate; global.set_head = set_head; global.set_tail = set_tail; +global.take = take; +global.drop = drop;