Skip to content

Commit 5ed4d40

Browse files
committed
Handle negative arguments in drop, resolves #52
With this change, `drop` handles negative arguments consistently: ``` purs drop (-2) "abcdef" == drop 0 "abcdef" == "abcdef" ```
1 parent 6e67dd1 commit 5ed4d40

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Data/String.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exports.take = function (n) {
118118

119119
exports.drop = function (n) {
120120
return function (s) {
121-
return s.substr(n);
121+
return s.substring(n);
122122
};
123123
};
124124

test/Test/Data/String.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ testString = do
131131
assert $ take 1 "ab" == "a"
132132
assert $ take 2 "ab" == "ab"
133133
assert $ take 3 "ab" == "ab"
134+
assert $ take (-1) "ab" == ""
134135

135136
log "drop"
136137
assert $ drop 0 "ab" == "ab"
137138
assert $ drop 1 "ab" == "b"
138139
assert $ drop 2 "ab" == ""
139140
assert $ drop 3 "ab" == ""
141+
assert $ drop (-1) "ab" == "ab"
140142

141143
log "count"
142144
assert $ count (\c -> true) "" == 0

0 commit comments

Comments
 (0)