on master help sign in
Add append and concat functions, organize docs better
commitabbcf3c13d2604ab3ab8f27756dd2cc431ec23bf authorEvan Czaplicki <info@elm-lang.org> dateTue 22 Oct 2013, 06:54 (13 years ago) parent99bd100
2 files changed+29−4
libraries/Native/String.js+8 libraries/String.elm+21−4
libraries/Native/String.js+8
@@ -22,6 +22,12 @@ Elm.Native.String.make = function(elm) {
2222 return (hd = str[0]) ? Maybe.Just(Utils.Tuple2(Utils.chr(hd), str.slice(1)))
2323 : Maybe.Nothing;
2424 }
25+ function append(a,b) {
26+ return a + b;
27+ }
28+ function concat(strs) {
29+ return JS.fromList(strs).join('');
30+ }
2531 function length(str) {
2632 return str.length;
2733 }
@@ -191,6 +197,8 @@ Elm.Native.String.make = function(elm) {
191197 isEmpty: isEmpty,
192198 cons: F2(cons),
193199 uncons: uncons,
200+ append: F2(append),
201+ concat: concat,
194202 length: length,
195203 map: F2(map),
196204 filter: F2(filter),
libraries/String.elm+21−4
@@ -3,11 +3,10 @@ module String where
33are enclosed in `"double quotes"`. Strings are *not* lists of characters.
44
55# Basics
6−@docs isEmpty, length, cons, uncons, reverse,
7− map, filter, foldl, foldr, any, all, repeat
6+@docs isEmpty, length, reverse, repeat
87
9−# Split and Join
10−@docs split, join, words, lines
8+# Building and Splitting
9+@docs cons, uncons, append, concat, split, join, words, lines
1110
1211# Get Substrings
1312@docs sub, left, right, dropLeft, dropRight
@@ -24,6 +23,9 @@ Cosmetic operations such as padding with extra characters or trimming whitespace
2423@docs toUpper, toLower,
2524 pad, padLeft, padRight,
2625 trim, trimLeft, trimRight
26+
27+# Higher-Order Functions
28+@docs map, filter, foldl, foldr, any, all
2729-}
2830
2931import Native.String
@@ -46,6 +48,21 @@ pattern match on strings exactly as you would with lists.
4648uncons : String -> Maybe (Char, String)
4749uncons = Native.String.uncons
4850
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+
4966{-| Get the length of a string `(length "innumerable" == 11)` -}
5067length : String -> Int
5168length = Native.String.length