Re: java.util.stream 'map' method, proposal of method name change

2017-08-21 Thread Krunoslav Magazin
Thank you all on comments. I have studied referenced sources and now I
will upgrade my initial comment in context of mentioned mutative
update. I find now that first question that need answer is what is the
definition of stream and how pipeline of operations relate to stream.

Method 'map' implies existence of materialized in/out streams. Example
is linear queue. This goes with definition on
https://en.m.wikipedia.org/wiki/Map_(higher-order_function) using list
as map source and output. Same I find in Haskell and Lisp usage of map
or mapcar function. Name of map function is indisputable as defined in
wiki resources. But is usage of that map function justified in java
streams ?
With java streams when implementation use operation fusion on pipeline
of operations there is no intermediary queue between operations.
https://www.ibm.com/developerworks/java/library/j-java-streams-1-brian-goetz/index.html?ca=drs-
chapter 'Stream versus collections', about fusion. This is
implementation specific ("how" to do it)

In common usage word stream represent current of elements. Stream
exist if there is at least one moving element. Without moving element
there is no stream. Stream have no state. Stream is agnostic on: 1)
element type; 2) source state; 3) target state.
This is how I see elements going through pipeline of operations when I
build sequence of operations ("what" to do with an element in
transition). Elements are emitted one by one from backed source
collection by stream() operation (stream source), going through
pipeline composed of filter() and map() operations, intermediate
operations like sorted() (ending one stream and emitting another) and
ending with the sink (collect(), count()...). Map method effectively
replaces element with computed one, stream doesn't care and source
collection is not affected. From this definition of stream goes that
operations are on the element, not on a stream (or collection with
state). This goes with my stand that word replace(With) would be
appropriate name for method, not map. If written description of stream
reflect streams library build up than usage of word map for method in
question is not justified here.

Article 
https://www.ibm.com/developerworks/java/library/j-java-streams-1-brian-goetz/index.html?ca=drs-
describe java streams library. It states that "Streams provide no
storage for the elements..." but in comment @Goetz said that 'replace'
implies mutative update. Am I missing something?


I will appreciate any comments.
Best regards,
Krunoslav Magazin


Re: java.util.stream 'map' method, proposal of method name change

2017-08-18 Thread Andrew Dinn
On 16/08/17 13:26, Remi Forax wrote:
> the name comes from Lisp
> https://en.m.wikipedia.org/wiki/Map_(higher-order_function)
Actually, the Lisp usage comes from mathematics:

  https://en.wikipedia.org/wiki/Map_(mathematics)

Since the original conception of Lisp was lambda calculus realised as a
programming language it should be no surprise that Lispers chose their
terminology from abstract algebra.

regards,


Andrew Dinn
---
Senior Principal Software Engineer
Red Hat UK Ltd
Registered in England and Wales under Company Registration No. 03798903
Directors: Michael Cunningham, Michael ("Mike") O'Neill, Eric Shander


Re: java.util.stream 'map' method, proposal of method name change

2017-08-16 Thread Remi Forax


On August 15, 2017 6:51:00 PM GMT+02:00, Jonathan Bluett-Duncan 
 wrote:
>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
>.
>
>(Why was it named that way? I admit I do not know, but someone else may
>be
>able to explain.)

the name comes from Lisp
https://en.m.wikipedia.org/wiki/Map_(higher-order_function)

>
>Hope this helps.
>
>Best regards,
>Jonathan

Remi 

>
>On 12 August 2017 at 03:36, Krunoslav Magazin 
>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
>>

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: java.util.stream 'map' method, proposal of method name change

2017-08-15 Thread Brian Goetz
Naming is a deeply subjective thing; whatever names we chose, invariably 
someone (or many someones) would come along and say "why didn't you 
choose X."  Sometimes there's a good reason why the proposed X is 
clearly worse; sometimes its just a subjective association.  But of 
course, we have to pick one name that is good enough for all Java 
developers, even if it is not ideal from some subjective viewpoints.


Names like `replaceWith` were actually considered, and rejected for a 
good reason:   words like "replace" have a connotation a mutative 
update.  This would be a good fit for in-place mutative methods like 
`List.replaceAll(T -> T)`, but a worse choice for a stream method.  
(You're free to disagree, of course.)


Regardless, changing method names on core abstractions like List or 
Stream is completely out of the question; this would be both a binary- 
and source-incompatible change (existing compiled classfiles would stop 
working; existing sources couldn't be recompiled.)  And adding an alias 
with a different name would be silly, unless the old name were so 
egregiously inappropriate as to be dangerous.





On 8/11/2017 10:36 PM, Krunoslav Magazin 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




Re: java.util.stream 'map' method, proposal of method name change

2017-08-15 Thread Jonathan Bluett-Duncan
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
.

(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  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
>


java.util.stream 'map' method, proposal of method name change

2017-08-15 Thread Krunoslav Magazin
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