4 ms·
Maybe it's because I'm not familiar with such style, but I don't like how the code hides operational details. That is, if `books` contains one billion books, a
by yongjik 2y ago
Maybe it's because I'm not familiar with such style, but I don't like how the code hides operational details. That is, if `books` contains one billion books, and the final result should contain about a hundred authors, how much extra memory does this use for intermediate results?
- yxhuvud 2y agoThis is a valid concern I also reacted a little bit on. One thing to note though is that it is often possible to tell such chains to be lazy and only collect the end result at the end without ever generating any intermediary arrays. Which require the author to actually have an idea how big the numbers are, but that is very often the case regardless of how you write your code.
- mrkeen 2y agoThe best way to kick the tyres on this kind of question is to plug in something literally infinite. That way if you arrive at an answer you're probably doing something right with regard to space and time usage. For example, use all the prime numbers as an expression in your chain. import Data.Function import Data.Numbers.Primes main = do let result :: [Int] = primes & filter (startingWithDigit '5') & asPairs & map pairSum & drop 100000 & take 10 print result asPairs xs = zip xs (tail xs) pairSum (a, b) = a + b startingWithDigit d x = d == head (show x) > [100960734,100960764,100960792,100960800,100960812] > 3 MiB total memory in use (0 MB lost due to fragmentation)