java.util.stream 'map' method, proposal of method name change
Jonathan Bluett-Duncan
jbluettduncan at gmail.com
Tue Aug 15 16:51:00 UTC 2017
Hi Krunoslav,
I think the reason the method was named `map` rather than `replaceWith` or
an equivalent name, is because `map` is a well-known name for this
sort of *higher-order
function*. The name itself has been around in functional programming
languages like Haskell and Scala and programming models like MapReduce for
decades.
Thus it would make sense to me that the writers of `java.util.stream` named
it `map` to follow the Principle of least astonishment
<https://en.wikipedia.org/wiki/Principle_of_least_astonishment>.
(Why was it named that way? I admit I do not know, but someone else may be
able to explain.)
Hope this helps.
Best regards,
Jonathan
On 12 August 2017 at 03:36, Krunoslav Magazin <magazin9 at gmail.com> wrote:
> Hi. When using java.util.stream 'map' method my opinion is that
> 'replaceWith' as method name would better describe what method do.
> 'map' method is applied on input stream, returns output stream but
> returned stream elements are return values from 'map' method Function
> argument. We continue our work with output stream so mapping with
> input stream have no meaning. Input stream is replaced with output
> stream which elements are outputs of Function. After that point we can
> forgot about input stream.
>
> Example of usage:
> now - stream.map(e -> e+2).. // read: map input stream with
> output stream containing elements resulting from function (e -> e+2)
> proposed - stream.replaceWith(e -> e+2).. // read: replace input
> stream with output stream containing elements resulting from function
> (e -> e+2)
>
> With 'map' method number of elements is the same but we do not make
> assumptions what passed Function will do (specialization) until the
> moment we pass Function implementation as method argument..
>
> I will appreciate any comments.
> Best regards,
> Krunoslav Magazin
>
More information about the core-libs-dev
mailing list