Skip to content

Commit 0291a2b

Browse files
committed
More Int usage, special cases for negative bounds
1 parent 87df441 commit 0291a2b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Data/Array.purs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ foreign import drop
214214
"""
215215
function drop (n) {
216216
return function (l) {
217-
return l.slice(n);
217+
return n < 1 ? l : l.slice(n);
218218
};
219219
}
220220
""" :: forall a. Int -> [a] -> [a]
@@ -226,7 +226,8 @@ dropWhile p xs = (span p xs).rest
226226

227227
-- | Keep only a number of elements from the start of an array, creating a new array.
228228
take :: forall a. Int -> [a] -> [a]
229-
take n = slice zero n
229+
take n xs | n < one = []
230+
| otherwise = slice zero n xs
230231

231232
-- | Calculate the longest initial subarray for which all element satisfy the specified predicate,
232233
-- | creating a new array.
@@ -381,27 +382,27 @@ foreign import filter
381382
}
382383
""" :: forall a. (a -> Boolean) -> [a] -> [a]
383384

384-
-- | Create an array containing a range of numbers, including both endpoints.
385+
-- | Create an array containing a range of integers, including both endpoints.
385386
foreign import range
386387
"""
387388
function range (start) {
388389
return function (end) {
389-
var i = ~~start, e = ~~end;
390+
var i = start;
390391
var step = i > e ? -1 : 1;
391392
var result = [i], n = 1;
392-
while (i !== e) {
393+
while (i !== end) {
393394
i += step;
394395
result[n++] = i;
395396
}
396397
return result;
397398
};
398399
}
399-
""" :: Number -> Number -> [Number]
400+
""" :: Int -> Int -> [Int]
400401

401402
infix 8 ..
402403

403404
-- | An infix synonym for `range`.
404-
(..) :: Number -> Number -> [Number]
405+
(..) :: Int -> Int -> [Int]
405406
(..) = range
406407

407408
-- | Apply a function to pairs of elements at the same index in two arrays,

0 commit comments

Comments
 (0)