Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add support for TypedArrays/arrayBuffer/nodejs' Buffer #716

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2834,8 +2834,8 @@
return function(xs) {
if (n < 0) return Nothing;

// Fast path for arrays.
if (Array.isArray (xs)) {
// Fast path for objects supporting `slice`.
if (xs.slice) { // we want to support TypedArrays e.i. buffers
return n <= xs.length ? Just (arrayCase (n, xs)) : Nothing;
}

Expand Down
3 changes: 3 additions & 0 deletions test/drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ test ('drop', () => {

eq (S.drop (-1) (Cons (1) (Cons (2) (Cons (3) (Nil))))) (S.Nothing);

// eq (S.unchecked.drop (0) (new Uint8Array([10, 20, 30, 40, 50]))) (S.unchecked.Just (new Uint8Array([10, 20, 30, 40, 50])));
eq (S.unchecked.drop (1) (new Uint8Array([10, 20, 30, 40, 50]))) (S.unchecked.Just (new Uint8Array([20, 30, 40, 50])));

});