replace case expressions with listToMaybe

This commit is contained in:
Daniel Barlow 2024-10-30 23:32:13 +00:00
parent 2befb534a1
commit a3d48100ae

View File

@ -17,6 +17,7 @@ import Control.Exception
import Data.List as List
import Data.List qualified
import Data.Map as Map
import Data.Maybe
import Data.Text qualified
import Data.Text.Lazy as T
import Data.Time
@ -87,32 +88,20 @@ elToPoint c =
>>= content
in Point
(Pos lat lon)
( case ele of
[e] -> Just $ asFloat e
_ -> Nothing
)
( (listToMaybe ele) >>= return . asFloat )
( case ts of
[e] -> case Data.Time.ISO8601.parseISO8601 (Data.Text.unpack e) of
Just utime -> utime
_ -> UTCTime (toEnum 0) 0
_ -> UTCTime (toEnum 0) 0
)
( case cadence of
[e] -> Just (asInt e)
_ -> Nothing
)
( case power of
[e] -> Just (asInt e)
_ -> Nothing
)
( (listToMaybe cadence) >>= return . asInt)
( (listToMaybe power) >>= return . asInt)
Nothing
where
asFloat v = (read (Data.Text.unpack v) :: Float)
asInt v = (read (Data.Text.unpack v) :: Int)
getAttr name =
case Map.lookup name attrs of
Just v -> asFloat v
_ -> 0
getAttr name = maybe 0 asFloat (Map.lookup name attrs)
_ -> mkPoint (Pos 0 0)
getPoints :: Cursor -> [Point]