Skip to content

Commit bc164b9

Browse files
committed
Rename count to countPrefix #81
1 parent 0e6048f commit bc164b9

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

src/Data/String.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ exports._slice = function (b) {
139139
};
140140
};
141141

142-
exports.count = function (p) {
142+
exports.countPrefix = function (p) {
143143
return function (s) {
144144
var i = 0;
145145
while (i < s.length && p(s.charAt(i))) i++;

src/Data/String.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Data.String
2929
, slice
3030
, stripPrefix
3131
, stripSuffix
32-
, count
32+
, countPrefix
3333
, split
3434
, splitAt
3535
, toCharArray
@@ -162,7 +162,7 @@ uncons s = Just { head: U.charAt zero s, tail: drop one s }
162162
-- | ```
163163
-- |
164164
takeWhile :: (Char -> Boolean) -> String -> String
165-
takeWhile p s = take (count p s) s
165+
takeWhile p s = take (countPrefix p s) s
166166

167167
-- | Returns the suffix remaining after `takeWhile`.
168168
-- |
@@ -171,7 +171,7 @@ takeWhile p s = take (count p s) s
171171
-- | ```
172172
-- |
173173
dropWhile :: (Char -> Boolean) -> String -> String
174-
dropWhile p s = drop (count p s) s
174+
dropWhile p s = drop (countPrefix p s) s
175175

176176
-- | Returns the substring at indices `[begin, end)`.
177177
-- | If either index is negative, it is normalised to `length s - index`,
@@ -407,10 +407,10 @@ dropRight i s = take (length s - i) s
407407
-- | of the string for which the predicate holds.
408408
-- |
409409
-- | ```purescript
410-
-- | count (_ /= ' ') "Hello World" == 5 -- since length "Hello" == 5
410+
-- | countPrefix (_ /= ' ') "Hello World" == 5 -- since length "Hello" == 5
411411
-- | ```
412412
-- |
413-
foreign import count :: (Char -> Boolean) -> String -> Int
413+
foreign import countPrefix :: (Char -> Boolean) -> String -> Int
414414

415415
-- | Returns the substrings of the second string separated along occurences
416416
-- | of the first string.

src/Data/String/CodePoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exports._codePointAt = function (fallback) {
4040
};
4141
};
4242

43-
exports._count = function (fallback) {
43+
exports._countPrefix = function (fallback) {
4444
return function (unsafeCodePointAt0) {
4545
if (hasStringIterator) {
4646
return function (pred) {

src/Data/String/CodePoints.purs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Data.String.CodePoints
99
, codePointFromInt
1010
, codePointToInt
1111
, codePointFromChar
12-
, count
12+
, countPrefix
1313
, drop
1414
, dropWhile
1515
, fromCodePointArray
@@ -168,14 +168,14 @@ codePointAtFallback n s = case uncons s of
168168
-- | time linear to the length of the string.
169169
-- |
170170
-- | ```purescript
171-
-- | >>> count (\c -> codePointToInt c == 0x1D400) "𝐀𝐀 b c 𝐀"
171+
-- | >>> countPrefix (\c -> codePointToInt c == 0x1D400) "𝐀𝐀 b c 𝐀"
172172
-- | 2
173173
-- | ```
174174
-- |
175-
count :: (CodePoint -> Boolean) -> String -> Int
176-
count = _count countFallback unsafeCodePointAt0
175+
countPrefix :: (CodePoint -> Boolean) -> String -> Int
176+
countPrefix = _countPrefix countFallback unsafeCodePointAt0
177177

178-
foreign import _count
178+
foreign import _countPrefix
179179
:: ((CodePoint -> Boolean) -> String -> Int)
180180
-> (String -> CodePoint)
181181
-> (CodePoint -> Boolean)
@@ -217,7 +217,7 @@ drop n s = String.drop (String.length (take n s)) s
217217
-- | ```
218218
-- |
219219
dropWhile :: (CodePoint -> Boolean) -> String -> String
220-
dropWhile p s = drop (count p s) s
220+
dropWhile p s = drop (countPrefix p s) s
221221

222222

223223
-- | Creates a string from an array of code points. Operates in space and time
@@ -402,7 +402,7 @@ takeFallback n s = case uncons s of
402402
-- | ```
403403
-- |
404404
takeWhile :: (CodePoint -> Boolean) -> String -> String
405-
takeWhile p s = take (count p s) s
405+
takeWhile p s = take (countPrefix p s) s
406406

407407

408408
-- | Creates an array of code points from a string. Operates in space and time

src/Data/String/NonEmpty.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module Data.String.NonEmpty
4141
, dropWhile
4242
, stripPrefix
4343
, stripSuffix
44-
, count
44+
, countPrefix
4545
, splitAt
4646
, toLower
4747
, toUpper
@@ -409,10 +409,10 @@ dropRight i (NonEmptyString s)
409409
-- | for which the predicate holds.
410410
-- |
411411
-- | ```purescript
412-
-- | count (_ /= 'o') (NonEmptyString "Hello World") == 4
412+
-- | countPrefix (_ /= 'o') (NonEmptyString "Hello World") == 4
413413
-- | ```
414-
count :: (Char -> Boolean) -> NonEmptyString -> Int
415-
count = liftS <<< String.count
414+
countPrefix :: (Char -> Boolean) -> NonEmptyString -> Int
415+
countPrefix = liftS <<< String.countPrefix
416416

417417
-- | Returns the substrings of a split at the given index, if the index is
418418
-- | within bounds.

test/Test/Data/String.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ testString = do
160160
assert $ dropRight 3 "ab" == ""
161161
assert $ dropRight (-1) "ab" == "ab"
162162

163-
log "count"
164-
assert $ count (_ == 'a') "" == 0
165-
assert $ count (_ == 'a') "ab" == 1
166-
assert $ count (_ == 'a') "aaab" == 3
167-
assert $ count (_ == 'a') "abaa" == 1
163+
log "countPrefix"
164+
assert $ countPrefix (_ == 'a') "" == 0
165+
assert $ countPrefix (_ == 'a') "ab" == 1
166+
assert $ countPrefix (_ == 'a') "aaab" == 3
167+
assert $ countPrefix (_ == 'a') "abaa" == 1
168168

169169
log "split"
170170
assert $ split (Pattern "") "" == []

test/Test/Data/String/CodePoints.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ testStringCodePoints = do
4141
assert $ Just (codePointFromChar $ fromCharCode 0) == codePointFromInt 0
4242
assert $ Just (codePointFromChar $ fromCharCode 0xFFFF) == codePointFromInt 0xFFFF
4343

44-
log "count"
45-
assert $ count (\_ -> true) "" == 0
46-
assert $ count (\_ -> false) str == 0
47-
assert $ count (\_ -> true) str == 7
48-
assert $ count (\x -> codePointToInt x < 0xFFFF) str == 4
49-
assert $ count (\x -> codePointToInt x < 0xDC00) str == 1
44+
log "countPrefix"
45+
assert $ countPrefix (\_ -> true) "" == 0
46+
assert $ countPrefix (\_ -> false) str == 0
47+
assert $ countPrefix (\_ -> true) str == 7
48+
assert $ countPrefix (\x -> codePointToInt x < 0xFFFF) str == 4
49+
assert $ countPrefix (\x -> codePointToInt x < 0xDC00) str == 1
5050

5151
log "drop"
5252
assert $ drop (-1) str == str

test/Test/Data/String/NonEmpty.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ testNonEmptyString = do
201201
assert $ dropRight 3 (nes "ab") == Nothing
202202
assert $ dropRight (-1) (nes "ab") == Just (nes "ab")
203203

204-
log "count"
205-
assert $ count (_ == 'a') (nes "ab") == 1
206-
assert $ count (_ == 'a') (nes "aaab") == 3
207-
assert $ count (_ == 'a') (nes "abaa") == 1
208-
assert $ count (_ == 'c') (nes "abaa") == 0
204+
log "countPrefix"
205+
assert $ countPrefix (_ == 'a') (nes "ab") == 1
206+
assert $ countPrefix (_ == 'a') (nes "aaab") == 3
207+
assert $ countPrefix (_ == 'a') (nes "abaa") == 1
208+
assert $ countPrefix (_ == 'c') (nes "abaa") == 0
209209

210210
log "splitAt"
211211
let

0 commit comments

Comments
 (0)