简单功能:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints tps =
map (\tp -> (time tp, distance tp, speed tp)) $
filter (\tp -> rpm tp > 10000) tps
相同,但尽可能无点:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints =
map (\tp -> (time tp, distance tp, speed tp)) .
filter ((> 10000) . rpm)
使用警卫:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints ((TP rpm time distance speed) : t)
| rpm > 10000 = (time, distance, speed) : processTrackPoints t
| otherwise = processTrackPoints t
processTrackPoints _ = []
当然,这就是所有假设,您已经正确定义了数据类型,如下所示:
data TrackPoint =
TP {
rpm :: Integer,
time :: Integer,
distance :: Float,
speed :: Float
}
deriving (Show)