2{-| A built-in representation for efficient string manipulation. String literals
3are enclosed in `"double quotes"`. Strings are *not* lists of characters.
6@docs isEmpty, length, cons, uncons, reverse,
7 map, filter, foldl, foldr, any, all, repeat
10@docs split, join, words, lines
13@docs sub, left, right, dropLeft, dropRight
16@docs contains, startsWith, endsWith, indexes, indices
18# Conversion To Numbers
22Cosmetic operations such as padding with extra characters or trimming whitespace.
24@docs toUpper, toLower,
25 pad, padLeft, padRight,
26 trim, trimLeft, trimRight
32{-| Check if a string is empty `(isEmpty "" == True)` -}
34isEmpty = Native.String.isEmpty
36{-| Add a character to the beginning of a string -}
37cons : Char -> String -> String
38cons = Native.String.cons
40{-| Split a non-empty string into its head and tail. This lets you
41pattern match on strings exactly as you would with lists.
43 uncons "abc" == Just ('a',"bc")
46uncons : String -> Maybe (Char, String)
47uncons = Native.String.uncons
49{-| Get the length of a string `(length "innumerable" == 11)` -}
51length = Native.String.length
53{-| Transform every character in a string
55 map (\c -> if c == '/' then '.' else c) "a/b/c" == "a.b.c"
57map : (Char -> Char) -> String -> String
58map = Native.String.map
60{-| Keep only the characters that satisfy the predicate:
62 filter isDigit "R2-D2" == "22"
64filter : (Char -> Bool) -> String -> String
65filter = Native.String.filter
67{-| Reverse a string. `(reverse "stressed" == "desserts")` -}
68reverse : String -> String
69reverse = Native.String.reverse
73foldl : (Char -> b -> b) -> b -> String -> b
74foldl = Native.String.foldl
78foldr : (Char -> b -> b) -> b -> String -> b
79foldr = Native.String.foldr
81{-| Split a string using a given separator.
83 split "," "cat,dog,cow" == ["cat","dog","cow"]
84 split "/" "home/evan/Desktop/" == ["home","evan","Desktop"]
86split : String -> String -> [String]
87split = Native.String.split
89{-| Put many strings together with a given separator.
91 join " " ["cat","dog","cow"] == "cat dog cow"
92 join "/" ["home","evan","Desktop"] == "home/evan/Desktop"
94join : String -> [String] -> String
95join = Native.String.join
97{-| Repeat a string N times `(repeat 3 "ha" == "hahaha")` -}
98repeat : Int -> String -> String
99repeat = Native.String.repeat
101{-| Take a substring given a start and end index. Negative indexes
102are taken starting from the *end* of the list.
104 sub 7 9 "snakes on a plane!" == "on"
105 sub 0 6 "snakes on a plane!" == "snakes"
106 sub 0 -7 "snakes on a plane!" == "snakes on a"
107 sub -6 -1 "snakes on a plane!" == "plane"
109sub : Int -> Int -> String -> String
110sub = Native.String.sub
112{-| Take N characters from the left side of a string. -}
113left : Int -> String -> String
114left = Native.String.left
116{-| Take N characters from the right side of a string. -}
117right : Int -> String -> String
118right = Native.String.right
120{-| Drop N characters from the left side of a string. -}
121dropLeft : Int -> String -> String
122dropLeft = Native.String.dropLeft
124{-| Drop N characters from the right side of a string. -}
125dropRight : Int -> String -> String
126dropRight = Native.String.dropRight
128{-| Pad a string on both sides until it has a given length.
130 pad 5 ' ' "1" == " 1 "
131 pad 5 ' ' "11" == " 11 "
132 pad 5 ' ' "121" == " 121 "
134pad : Int -> Char -> String -> String
135pad = Native.String.pad
137{-| Pad a string on the left until it has a given length.
139 pad 5 '.' "1" == "....1"
140 pad 5 '.' "11" == "...11"
141 pad 5 '.' "121" == "..121"
143padLeft : Int -> Char -> String -> String
144padLeft = Native.String.padLeft
146{-| Pad a string on the right until it has a given length.
148 pad 5 '.' "1" == "1...."
149 pad 5 '.' "11" == "11..."
150 pad 5 '.' "121" == "121.."
152padRight : Int -> Char -> String -> String
153padRight = Native.String.padRight
155{-| Get rid of whitespace on both sides of a string.
157 trim " hats \n" == "hats"
159trim : String -> String
160trim = Native.String.trim
162{-| Get rid of whitespace on the left of a string.
164 trimLeft " hats \n" == "hats \n"
166trimLeft : String -> String
167trimLeft = Native.String.trimLeft
169{-| Get rid of whitespace on the left of a string.
171 trimRight " hats \n" == " hats"
173trimRight : String -> String
174trimRight = Native.String.trimRight
176{-| Break a string into words, splitting on chunks of whitespace.
178 words "How are \t you? \n Good?" == ["How","are","you?","Good?"]
180words : String -> [String]
181words = Native.String.words
183{-| Break a string into lines, splitting on newlines.
185 lines "How are you?\nGood? == ["How are you?", "Good?"]
187lines : String -> [String]
188lines = Native.String.lines
190{-| Convert a string to all upper case. Useful for case insensitive comparisons
193toUpper : String -> String
194toUpper = Native.String.toUpper
196{-| Convert a string to all lower case. Useful for case insensitive comparisons. -}
197toLower : String -> String
198toLower = Native.String.toLower
200{-| Check to see if *any* characters satisfy a predicate.
202 any isDigit "90210" == True
203 any isDigit "R2-D2" == True
204 any isDigit "heart" == False
206any : (Char -> Bool) -> String -> Bool
207any = Native.String.any
209{-| Check to see if *all* characters satisfy a predicate.
211 all isDigit "90210" == True
212 all isDigit "R2-D2" == False
213 any isDigit "heart" == False
215all : (Char -> Bool) -> String -> Bool
216all = Native.String.all
218{-| See if a string contains another one.
220 contains "the" "theory" == True
221 contains "hat" "theory" == False
222 contains "THE" "theory" == False
224contains : String -> String -> Bool
225contains = Native.String.contains
227{-| See if a string starts with another one.
229 startsWith "the" "theory" == True
230 startsWith "ory" "theory" == False
232startsWith : String -> String -> Bool
233startsWith = Native.String.startsWith
235{-| See if a string ends with another one.
237 endsWith "the" "theory" == False
238 endsWith "ory" "theory" == True
240endsWith : String -> String -> Bool
241endsWith = Native.String.endsWith
243{-| Get all of the indexes for a substring.
245 indexes "i" "Mississippi" == [1,4,7,10]
246 indexes "ss" "Mississippi" == [2,5]
247 indexes "needle" "haystack" == []
249indexes : String -> String -> [Int]
250indexes = Native.String.indexes
252{-| Alias for `indexes` -}
253indices : String -> String -> [Int]
254indices = Native.String.indexes
256{-| Try to convert a string into an int, failing on improperly formatted strings.
258 toInt "123" == Just 123
259 toInt "-42" == Just -42
260 toInt "3.1" == Nothing
261 toInt "31a" == Nothing
263toInt : String -> Maybe Int
264toInt = Native.String.toInt
266{-| Try to convert a string into a float, failing on improperly formatted strings.
268 toFloat "123" == Just 123.0
269 toFloat "-42" == Just -42.0
270 toFloat "3.1" == Just 3.1
271 toFloat "31a" == Nothing
273toFloat : String -> Maybe Float
274toFloat = Native.String.toFloat
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