1module Data.String.Extra
6||| Adds a character to the end of the specified string.
14strSnoc : String -> Char -> String
15strSnoc s c = s ++ (singleton c)
22(+>) : String -> Char -> String
30(<+) : Char -> String -> String
33||| Take the first `n` characters from a string. Returns the whole string
35take : (n : Nat) -> (input : String) -> String
36take n str = substr Z n str
38||| Take the last `n` characters from a string. Returns the whole string
40takeLast : (n : Nat) -> (input : String) -> String
41takeLast n str with (length str)
42 takeLast n str | len with (isLTE n len)
43 takeLast n str | len | Yes prf = substr (len - n) len str
44 takeLast n str | len | No contra = str
46||| Remove the first `n` characters from a string. Returns the empty string if
47||| the input string is too short.
48drop : (n : Nat) -> (input : String) -> String
49drop n str = substr n (length str) str
51||| Remove the last `n` characters from a string. Returns the empty string if
52||| the input string is too short.
53dropLast : (n : Nat) -> (input : String) -> String
54dropLast n str = reverse (drop n (reverse str))
56||| Remove the first and last `n` characters from a string. Returns the empty
57||| string if the input string is too short.
58shrink : (n : Nat) -> (input : String) -> String
59shrink n str = dropLast n (drop n str)
61||| Concatenate the strings from a `Foldable` containing strings, separated by
63join : (sep : String) -> Foldable t => (xs : t String) -> String
64join sep xs = drop (length sep)
65 (foldl (\acc, x => acc ++ sep ++ x) "" xs)
67||| Get a character from a string if the string is long enough.
68index : (n : Nat) -> (input : String) -> Maybe Char
69index n str with (unpack str)
70 index n str | [] = Nothing
71 index Z str | (x :: xs) = Just x
72 index (S n) str | (x :: xs) = index n str | xs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list