Use list comprehensions instead of clunky combinations of map and filter

This commit is contained in:
Joseph C. Sible 2020-02-01 22:50:20 -05:00
parent f25b8bd03a
commit e6e89d68fd
2 changed files with 4 additions and 4 deletions

View file

@ -295,7 +295,7 @@ prop_pstreeSumsCorrectly kvs targets =
-- Trivial O(n * m) implementation
dumbPrefixSums :: [(Int, Int)] -> [Int] -> [Int]
dumbPrefixSums kvs targets =
let prefixSum target = sum . map snd . filter (\(k,v) -> k <= target) $ kvs
let prefixSum target = sum [v | (k,v) <- kvs, k <= target]
in map prefixSum targets
-- PSTree O(n * log m) implementation
smartPrefixSums :: [(Int, Int)] -> [Int] -> [Int]