commit a3d48100ae5a2dfc017e085c53722efc80c8e515
parent 2befb534a17c45cc8d1a6541362efe0db421ca25
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 30 Oct 2024 23:32:13 +0000
replace case expressions with listToMaybe
Diffstat:
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/lib/Track.hs b/lib/Track.hs
@@ -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]