Why is Ruby Array.map () also called Array.collect ()?

Whenever I see Ruby code that says:

arrayNames.collect { ... }

I forgot what collection is, and I need to look at what it is and find that it is the same as map ().

I can understand that mapping is 1 byte per pixel, and the function is mapping x to ay, from 2 to 4, from 5 to 25, etc. But where does the name “collect” come from? Perhaps this will help to recall what the “assemble” method is.

+3
source share
3 answers

To add to the other answers, this will be a joke inside Smalltalk:

  • inject:into:
  • collect:
  • select:
  • reject:
  • detect:

Define a pattern?

+4
source

Smalltalk . Smalltalk collect select map filter ( ) .

+5

kriss is true that the method name originates in Smalltalk, but to remember what it does when you see it, you can think of it as "collecting results from a block in a new array".

+3
source

Source: https://habr.com/ru/post/1752786/


All Articles