NoRedInk/elm-string-conversions/1.0.1

String.Conversions

Helpers to convert common types into a String.

fromBool : Bool -> String

Convert a Bool to a String matching its constructor.

fromWeekday : Weekday -> String

Convert a Time.Weekday to a String matching its constructor.

fromDict : (comparable -> String) -> (v -> String) -> Dict comparable v -> String

Convert a Dict to a String using nested conversions.

import Dict


fromDict String.fromInt String.fromFloat (Dict.fromList [(1, 1.5)])
--> "Dict.fromList [(1,1.5)]"
fromHttpError : Error -> String

Convert an Http.Error to a String.

fromHttpResponse : Response String -> String

Convert an Http.Response String to a String.

fromList : (a -> String) -> List a -> String

Convert a List to a string using a nested conversion.

fromList String.fromInt [1, 2, 3]
--> "[1,2,3]"
fromMaybe : (a -> String) -> Maybe a -> String

Convert a Maybe to a String using a nested conversion.

fromMaybe String.fromInt (Just 1)
--> "Just 1"
fromMonth : Month -> String

Convert a Time.Month to a String matching its constructor.

fromRecord : List ( String, a -> String ) -> a -> String

Build a record string for debugging and logging with pairs of keys and string conversion functions, meant to be paired with accessors

fromRecord [ ("hello", .hello >> String.fromInt ) ] { hello = 1 }
--> "{ hello = 1 }"
fromSet : (comparable -> String) -> Set comparable -> String

Convert a Set to a string using a nested conversion.

import Set


fromSet String.fromInt (Set.fromList [1, 2])
--> "Set.fromList [1,2]"
fromString : String -> String

Convert a String to a debugging version of that String.

fromString "hello \"world\""
--> "\"hello \\\"world\\\"\""
fromTuple2 : (a -> String) -> (b -> String) -> ( a, b ) -> String

Convert a 2-tuple to a string using nested conversions.

fromTuple2 String.fromInt String.fromFloat ( 1, 1.5 )
--> "(1,1.5)"
fromTuple3 : (a -> String) -> (b -> String) -> (c -> String) -> ( a, b, c ) -> String

Convert a 3-tuple to a string using nested conversions.

fromTuple3 String.fromInt String.fromFloat String.fromInt ( 1, 1.5, 2 )
--> "(1,1.5,2)"
fromValue : Value -> String

Convert a Json.Decode.Value to a JSON String.

withUnionConstructor : String -> List String -> String

Nest some arguments under a tag, including parentheses when needed. Helpful for printing union type values.

withUnionConstructor "Ok" [ String.fromInt 1 ]
--> "Ok 1"