From a3d48100ae5a2dfc017e085c53722efc80c8e515 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 30 Oct 2024 23:32:13 +0000 Subject: [PATCH] replace case expressions with listToMaybe --- lib/Track.hs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/Track.hs b/lib/Track.hs index d48246c..6b72663 100644 --- 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]