Last active
October 7, 2018 08:52
-
-
Save monomadic/8f695095da519d7961e4faf97e160cdf to your computer and use it in GitHub Desktop.
Convert a float to an int with JSON.Decode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Json.Decode as Decode | |
type alias CoinPair = { pair: String, price: Float, rsi_15m: Int } | |
decodeCoinPair : Decode.Decoder CoinPair | |
decodeCoinPair = | |
Decode.map5 CoinPair | |
(Decode.field "pair" Decode.string) | |
(Decode.field "price" Decode.float) | |
(Decode.field "rsi_15m" decodeFloatAsInt) | |
decodeFloatAsInt : Decode.Decoder Int | |
decodeFloatAsInt = | |
Decode.map | |
round(Decode.oneOf [Decode.float, Decode.null 0.0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment