@@ -21,8 +21,10 @@ module Data.String
21
21
, replace
22
22
, replaceAll
23
23
, take
24
+ , takeRight
24
25
, takeWhile
25
26
, drop
27
+ , dropRight
26
28
, dropWhile
27
29
, stripPrefix
28
30
, stripSuffix
@@ -274,8 +276,8 @@ foreign import _lastIndexOf
274
276
-> Maybe Int
275
277
276
278
-- | Returns the index of the last occurrence of the pattern in the
277
- -- | given string, starting at the specified index
278
- -- | and searching backwards towards the beginning of the string.
279
+ -- | given string, starting at the specified index
280
+ -- | and searching backwards towards the beginning of the string.
279
281
-- | Returns `Nothing` if there is no match.
280
282
-- |
281
283
-- | ```purescript
@@ -347,6 +349,15 @@ foreign import replaceAll :: Pattern -> Replacement -> String -> String
347
349
-- |
348
350
foreign import take :: Int -> String -> String
349
351
352
+ -- | Returns the last `n` characters of the string.
353
+ -- |
354
+ -- | ```purescript
355
+ -- | take 5 "Hello World" == "World"
356
+ -- | ```
357
+ -- |
358
+ takeRight :: Int -> String -> String
359
+ takeRight i s = drop (length s - i) s
360
+
350
361
-- | Returns the string without the first `n` characters.
351
362
-- |
352
363
-- | ```purescript
@@ -355,6 +366,15 @@ foreign import take :: Int -> String -> String
355
366
-- |
356
367
foreign import drop :: Int -> String -> String
357
368
369
+ -- | Returns the string without the last `n` characters.
370
+ -- |
371
+ -- | ```purescript
372
+ -- | dropRight 6 "Hello World" == "Hello"
373
+ -- | ```
374
+ -- |
375
+ dropRight :: Int -> String -> String
376
+ dropRight i s = take (length s - i) s
377
+
358
378
-- | Returns the number of contiguous characters at the beginning
359
379
-- | of the string for which the predicate holds.
360
380
-- |
0 commit comments