From abbcf3c13d2604ab3ab8f27756dd2cc431ec23bf Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Tue, 22 Oct 2013 06:54:09 +0200 Subject: [PATCH] Add append and concat functions, organize docs better --- libraries/Native/String.js | 8 ++++++++ libraries/String.elm | 25 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libraries/Native/String.js b/libraries/Native/String.js index 4c03eb0..5d6a421 100644 --- a/libraries/Native/String.js +++ b/libraries/Native/String.js @@ -22,6 +22,12 @@ Elm.Native.String.make = function(elm) { return (hd = str[0]) ? Maybe.Just(Utils.Tuple2(Utils.chr(hd), str.slice(1))) : Maybe.Nothing; } + function append(a,b) { + return a + b; + } + function concat(strs) { + return JS.fromList(strs).join(''); + } function length(str) { return str.length; } @@ -191,6 +197,8 @@ Elm.Native.String.make = function(elm) { isEmpty: isEmpty, cons: F2(cons), uncons: uncons, + append: F2(append), + concat: concat, length: length, map: F2(map), filter: F2(filter), diff --git a/libraries/String.elm b/libraries/String.elm index 4793dd1..67c607c 100644 --- a/libraries/String.elm +++ b/libraries/String.elm @@ -3,11 +3,10 @@ module String where are enclosed in `"double quotes"`. Strings are *not* lists of characters. # Basics -@docs isEmpty, length, cons, uncons, reverse, - map, filter, foldl, foldr, any, all, repeat +@docs isEmpty, length, reverse, repeat -# Split and Join -@docs split, join, words, lines +# Building and Splitting +@docs cons, uncons, append, concat, split, join, words, lines # Get Substrings @docs sub, left, right, dropLeft, dropRight @@ -24,6 +23,9 @@ Cosmetic operations such as padding with extra characters or trimming whitespace @docs toUpper, toLower, pad, padLeft, padRight, trim, trimLeft, trimRight + +# Higher-Order Functions +@docs map, filter, foldl, foldr, any, all -} import Native.String @@ -46,6 +48,21 @@ pattern match on strings exactly as you would with lists. uncons : String -> Maybe (Char, String) uncons = Native.String.uncons +{-| Append two strings. You can also use [the `(++)` operator](/library/List.elm#++) +to do this. + + append "butter" "fly" == "butterfly" +-} +append : String -> String -> String +append = Native.String.append + +{-| Concatenate many strings into one. + + concat ["never","the","less"] == "nevertheless" +-} +concat : [String] -> String +concat = Native.String.concat + {-| Get the length of a string `(length "innumerable" == 11)` -} length : String -> Int length = Native.String.length