Skip to content
Merged
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
3 changes: 2 additions & 1 deletion docs/Data/String.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ Returns the string without the first `n` characters.
count :: (Char -> Boolean) -> String -> Int
```

Returns the number of characters in the string for which the predicate holds.
Returns the number of contiguous characters at the beginning
of the string for which the predicate holds.

#### `split`

Expand Down
7 changes: 7 additions & 0 deletions src/Data/String.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ exports.drop = function (n) {
};
};

exports.count = function (p) {
return function (s) {
for (var i = 0; i < s.length && p(s.charAt(i)); i++); {}
return i;
};
};

exports.split = function (sep) {
return function (s) {
return s.split(sep);
Expand Down
3 changes: 2 additions & 1 deletion src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ foreign import take :: Int -> String -> String
-- | Returns the string without the first `n` characters.
foreign import drop :: Int -> String -> String

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

-- | Returns the substrings of the first string separated along occurences
Expand Down