Is “map” a loop?

后端 未结 15 1963
自闭症患者
自闭症患者 2020-12-14 14:29

While answering this question, I came to realize that I was not sure whether Perl\'s map can be considered a loop or not?

On one hand, it quacks/walks l

15条回答
  •  执笔经年
    2020-12-14 15:15

    It all depends on how you look at it...

    On the one hand, Perl's map can be considered a loop, if only because that's how it's implemented in (current versions of) Perl.

    On the other, though, I view it as a functional map and choose to use it accordingly which, among other things, includes only making the assumption that all elements of the list will be visited, but not making any assumptions about the order in which they will be visited. Aside from the degree of functional purity this brings and giving map a reason to exist and be used instead of for, this also leaves me in good shape if some future version of Perl provides a parallelizable implementation of map. (Not that I have any expectation of that ever happening...)

提交回复
热议问题