News for hackers. Stuff that matters.
Re:Swift and the Legacy of Functional Programming by skizm on Monday November 21, 2016 @03:21PM (#13008812)
Is the first one two loops or one?
Re:Swift and the Legacy of Functional Programming by mikeash on Monday November 21, 2016 @04:02PM (#13009187)
Two. These methods are not lazy by default. Of course, you have to know the language pretty well to know that, but I do. For anyone wondering, you can write names.lazy.map(...) to get lazy evaluation.
Re:Swift and the Legacy of Functional Programming by chii on Monday November 21, 2016 @08:16PM (#13010827)
The real answer is that it doesn't matter. Just like for most code, the output assembly or machine code doesn't matter.
Re:Swift and the Legacy of Functional Programming by actsasbuffoon on Monday November 21, 2016 @04:01PM (#13009180)
It depends. Using lazy data structures, transducers, or a number of other common tricks would turn it into one loop. Haskell, Clojure, Ruby, Scala, Swift, and many other languages make it pretty easy to do.
Re:Swift and the Legacy of Functional Programming by andreareina on Tuesday November 22, 2016 @12:35AM (#13011876)
Naïvely, two. The compiler can probably figure out that the semantics are the same and choose depending on what its model says will be faster.