A symbol code is usually used in a Symbol, along with a precision.
The symbol code is the "name" of the symbol. For example, the symbol 0,ABC
has
precision 0
and symbol code ABC
.
A symbol code is a String
of up to 7 characters, consisting of uppercase letters
from A-Z.
String
toString : SymbolCode -> String
Convert a SymbolCode to a String
fromString "EOS"
|> Result.map toString
--> Ok "EOS"
fromString : String -> Result Error SymbolCode
Convert a String
into a SymbolCode. A SymbolCode must be
a String
of up to 7 characters, all uppercase letters (A-Z).
fromString "Test"
--> Err (InvalidCharacters ( 'e', [ 's', 't' ] ))
fromString "VERYLONG"
--> Err TooLong
fromString "EOS"
|> Result.map toString
--> Ok ("EOS")
Converting a String
into a SymbolCode
(with fromString)
can fail. This type represents all of the possible errors.
fromString "Test"
--> Err (InvalidCharacters ( 'e', [ 's', 't' ] ))
fromString "VERYLONG"
--> Err TooLong
fromString "EOS"
|> Result.map toString
--> Ok ("EOS")
errorToString : Error -> String
You can use this function to convert an Error into a human-readable
String
.
encode : SymbolCode -> Json.Encode.Value
Encode a SymbolCode into JSON.
decoder : Json.Decode.Decoder SymbolCode
Decode a SymbolCode from JSON. It already does all of the validation necessary to ensure the SymbolCode is valid.