on master help sign in
Add append and concat functions, organize docs better
abbcf3cEvan Czaplicki
libraries/Native/String.js+8
@@ -22,6 +22,12 @@ Elm.Native.String.make = function(elm) {
22 return (hd = str[0]) ? Maybe.Just(Utils.Tuple2(Utils.chr(hd), str.slice(1)))
22 return (hd = str[0]) ? Maybe.Just(Utils.Tuple2(Utils.chr(hd), str.slice(1)))
23 : Maybe.Nothing;
23 : Maybe.Nothing;
24 }
24 }
25+ function append(a,b) {
26+ return a + b;
27+ }
28+ function concat(strs) {
29+ return JS.fromList(strs).join('');
30+ }
25 function length(str) {
31 function length(str) {
26 return str.length;
32 return str.length;
27 }
33 }
@@ -191,6 +197,8 @@ Elm.Native.String.make = function(elm) {
191 isEmpty: isEmpty,
197 isEmpty: isEmpty,
192 cons: F2(cons),
198 cons: F2(cons),
193 uncons: uncons,
199 uncons: uncons,
200+ append: F2(append),
201+ concat: concat,
194 length: length,
202 length: length,
195 map: F2(map),
203 map: F2(map),
196 filter: F2(filter),
204 filter: F2(filter),
libraries/String.elm+21−4
@@ -3,11 +3,10 @@ module String where
3are enclosed in `"double quotes"`. Strings are *not* lists of characters.
3are enclosed in `"double quotes"`. Strings are *not* lists of characters.
4
4
5# Basics
5# Basics
6−@docs isEmpty, length, cons, uncons, reverse,
6+@docs isEmpty, length, reverse, repeat
7− map, filter, foldl, foldr, any, all, repeat
8
7
9−# Split and Join
8+# Building and Splitting
10−@docs split, join, words, lines
9+@docs cons, uncons, append, concat, split, join, words, lines
11
10
12# Get Substrings
11# Get Substrings
13@docs sub, left, right, dropLeft, dropRight
12@docs sub, left, right, dropLeft, dropRight
@@ -24,6 +23,9 @@ Cosmetic operations such as padding with extra characters or trimming whitespace
24@docs toUpper, toLower,
23@docs toUpper, toLower,
25 pad, padLeft, padRight,
24 pad, padLeft, padRight,
26 trim, trimLeft, trimRight
25 trim, trimLeft, trimRight
26+
27+# Higher-Order Functions
28+@docs map, filter, foldl, foldr, any, all
27-}
29-}
28
30
29import Native.String
31import Native.String
@@ -46,6 +48,21 @@ pattern match on strings exactly as you would with lists.
46uncons : String -> Maybe (Char, String)
48uncons : String -> Maybe (Char, String)
47uncons = Native.String.uncons
49uncons = Native.String.uncons
48
50
51+{-| Append two strings. You can also use [the `(++)` operator](/library/List.elm#++)
52+to do this.
53+
54+ append "butter" "fly" == "butterfly"
55+-}
56+append : String -> String -> String
57+append = Native.String.append
58+
59+{-| Concatenate many strings into one.
60+
61+ concat ["never","the","less"] == "nevertheless"
62+-}
63+concat : [String] -> String
64+concat = Native.String.concat
65+
49{-| Get the length of a string `(length "innumerable" == 11)` -}
66{-| Get the length of a string `(length "innumerable" == 11)` -}
50length : String -> Int
67length : String -> Int
51length = Native.String.length
68length = Native.String.length