hg: lambda/lambda/jdk: Remove FlatMapper and relevant flatMap variants; migrate to flatMap(e -> stream)
Marc Petit-Huguenin
marc at petit-huguenin.org
Tue May 21 14:54:55 PDT 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
On 05/21/2013 02:45 PM, Marc Petit-Huguenin wrote:
> On 04/09/2013 02:43 PM, Peter Levart wrote:
>
>> On 04/09/2013 11:27 PM, Marc Petit-Huguenin wrote: On 04/09/2013 01:59
>> PM, Mike Duigou wrote:
>>>>> FlatMapper alternatives are available. At this point the API is
>>>>> still undergoing refinement. This and many other things are still
>>>>> likely to change before the Java 8 streams API is complete. Our
>>>>> focus is on making the best long term decisions for Java and not
>>>>> the short term convenience of early adopters (think of yourselves
>>>>> as experimental volunteers).
>>>>>
>>>>> If you absolutely can't live without the APIs mentioned you need to
>>>>> explain why they are essential and why the alternatives are
>>>>> inadequate/inferior.
>> The minimum I can't absolutely live without is a Turing machine, so
>> don't mind me. It's just that is it the 3rd time that something I really
>> like is removed from the stream API.
>
>>> Is there a proof that Stream API is Turing complete ?-)
>
> I do not think that the Stream API is Turing complete as it is. But it can
> be if there is a way to loop the elements back to the source (probably not
> a good idea).
>
Attachment was removed:
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;
public class Test {
static<T> Stream<T> stream(Queue<T> queue) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new
Iterator<T>() {
public T next() {
return queue.remove();
}
public boolean hasNext() {
return queue.peek() != null;
}
}, Spliterator.NONNULL));
}
static Consumer<String> cyclicTagSystem(Queue<String> queue, String...
productions) {
return new Consumer<String>() {
private int counter = 0;
public void accept(String word) {
if (!word.equals("0")) {
queue.add(word.charAt(0) == '0' ? word.substring(1) :
(word.substring(1) + productions[counter]));
counter = (counter + 1) % productions.length;
}
}
};
}
public static void main(String[] args)
throws Exception {
Queue<String> queue = new LinkedList<>(Arrays.asList("1"));
stream(queue)
.peek(cyclicTagSystem(queue, "110", "01", "0000"))
.forEach(System.out::println);
}
}
- --
Marc Petit-Huguenin
Email: marc at petit-huguenin.org
Blog: http://blog.marc.petit-huguenin.org
Profile: http://www.linkedin.com/in/petithug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iQIcBAEBCAAGBQJRm+0rAAoJECnERZXWan7EAjoP/05NvO3LeJKjo2fCg5iqTOT9
6TeUywMhraQ5ZQGOAMnvpiCK0o4o+MYwlbqm+qCtB6Sz9k6hM7ahZWtJDO5LAXak
dU5UypunnMf2CKv0p73+C3jasyy/l2KnoFR6WmN8d8JTk9rLMyAybh/9xicX54Be
FO4b59NfglpDfi5bs4ys+eqjg7YqqPkgZOa+YrItoPTflXEOfjKBLDFAuMSXLbu5
7lPrbEjlPvYHEz6eC1n8fN7hr7Lq8gMKrlENl1vPoQvsqiXZdvQkQGOc0tDO1OxH
s9Q8gFJ2dsZTnr8/jhKYruytT/tXyk03ELPZUVWyfWj6TogvNx7tVBSm9Ib8V9G/
VzlwGkOz1OoQXB0HGLFyayYwqOFNESMagTKSa8xmJG0nXzIb8IocLxZuizZI/cd8
NOk/btjZWAtI2odO0ha+Ra0J+tY/KJVo/lmI+aK+/N7lq5ODdbavK+zC15iEnbTp
6WTGhcNv2OdwH9tRlh1RWjN5H8tTLgisWN7YnJDIQ741FwqQOLSv4DRim/QR5lNh
JKb+HBMU8bC2l7HVqR5QXC0EI+2AoAqKBV4jXh81MSo3LzgtkZySGviBE4WgeWHh
KFaNLeGBJXKr8UjV8FTxNHdOpZHPQo0DO25avHyF+2Oxx9YWbzhoPyWjhbHMm7T8
ugEY25IEIsfEFNYPDX5W
=6tlG
-----END PGP SIGNATURE-----
More information about the lambda-dev
mailing list