Skip to content

Commit 710382e

Browse files
committed
Merge pull request #35 from flipstone/fix_missing_foreign_count
Fix missing foreign `count` function.
2 parents cc08e3f + e1b1aec commit 710382e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/Data/String.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ Returns the string without the first `n` characters.
178178
count :: (Char -> Boolean) -> String -> Int
179179
```
180180

181-
Returns the number of characters in the string for which the predicate holds.
181+
Returns the number of contiguous characters at the beginning
182+
of the string for which the predicate holds.
182183

183184
#### `split`
184185

src/Data/String.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ exports.drop = function (n) {
120120
};
121121
};
122122

123+
exports.count = function (p) {
124+
return function (s) {
125+
for (var i = 0; i < s.length && p(s.charAt(i)); i++); {}
126+
return i;
127+
};
128+
};
129+
123130
exports.split = function (sep) {
124131
return function (s) {
125132
return s.split(sep);

src/Data/String.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ foreign import take :: Int -> String -> String
172172
-- | Returns the string without the first `n` characters.
173173
foreign import drop :: Int -> String -> String
174174

175-
-- | Returns the number of characters in the string for which the predicate holds.
175+
-- | Returns the number of contiguous characters at the beginning
176+
-- | of the string for which the predicate holds.
176177
foreign import count :: (Char -> Boolean) -> String -> Int
177178

178179
-- | Returns the substrings of the first string separated along occurences

0 commit comments

Comments
 (0)