简体   繁体   中英

Scala Map -> Reduce vs. FoldRight

I timed the the following two, and it appears that both of them take the same amount of time. Is there any benefit of using over the other?

(1 to 24).foldRight(List[Int]())((i, l) => l ::: generateList(signs, i))

vs.

(1 to 24).map(i => generateList(signs, i)).reduce(_ ::: _)

ps in my use case the order does not matter.

foldRight operates in order, map is (theoretically) parallelizable because it's order is not defined. I do not believe that it is parallel in the current scala runtime- just that it might be in the future or on different platforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM