Skip to content

Commit 9f5d65b

Browse files
Update documentation for splitAt
1 parent ad0bf43 commit 9f5d65b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Data/String.purs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,19 @@ foreign import count :: (Char -> Boolean) -> String -> Int
232232
foreign import split :: Pattern -> String -> Array String
233233

234234
-- | Returns a string split into two substrings at the given index, where
235-
-- | `before` includes all of the characters up to the given index, and `after`
236-
-- | is the rest of the string, from the given index on.
235+
-- | `before` includes all of the characters up to (but not including) the
236+
-- | given index, and `after` is the rest of the string, from the given index
237+
-- | on.
238+
-- |
239+
-- | Thus the length of `(splitAt i s).before` will equal either `i` or
240+
-- | `length s`, if that is shorter. (Or if `i` is negative the length will be
241+
-- | 0.)
242+
-- |
243+
-- | In code:
244+
-- | ```purescript
245+
-- | length (splitAt i s).before == min (max i 0) (length s)
246+
-- | (splitAt i s).before <> (splitAt i s).after == s
247+
-- | ```
237248
foreign import splitAt :: Int -> String -> { before :: String, after :: String }
238249

239250
-- | Converts the string into an array of characters.

0 commit comments

Comments
 (0)