Skip to content

Commit e7519dd

Browse files
committed
add slice
1 parent b69dff8 commit e7519dd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Data/String.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ exports.drop = function (n) {
131131
};
132132
};
133133

134+
exports.slice = function (b) {
135+
return function (e) {
136+
return function (s) {
137+
return s.slice(b, e);
138+
};
139+
};
140+
};
141+
134142
exports.count = function (p) {
135143
return function (s) {
136144
var i = 0;

src/Data/String.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Data.String
2626
, drop
2727
, dropRight
2828
, dropWhile
29+
, slice
2930
, stripPrefix
3031
, stripSuffix
3132
, count
@@ -172,6 +173,17 @@ takeWhile p s = take (count p s) s
172173
dropWhile :: (Char -> Boolean) -> String -> String
173174
dropWhile p s = drop (count p s) s
174175

176+
-- | Returns the substring at indices [begin, end).
177+
-- | If either index is negative, it is normalized to `length s - index`,
178+
-- | where `s` is the input string. An empty string is returned if either
179+
-- | index is out of bounds or if `begin > end`.
180+
-- |
181+
-- | ```purescript
182+
-- | slice 0 1 "purescript" == "p"
183+
-- | slice 3 6 "purescript" == "ecr"
184+
-- | slice -4 -1 "purescript" == "rip"
185+
foreign import slice :: Int -> Int -> String -> String
186+
175187
-- | If the string starts with the given prefix, return the portion of the
176188
-- | string left after removing it, as a Just value. Otherwise, return Nothing.
177189
-- |

0 commit comments

Comments
 (0)