Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Puzzler: Fun with Streams. Date: Wed, 13 May 2015 08:21:35 -0400 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 13 May 2015 12:22:26 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e164d158183579609bf09837dee5210"; logging-data="18013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+22mBMWOhAmwY508+1oo/eVtvsXa4hJ0c=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 In-Reply-To: Cancel-Lock: sha1:NPFqDl+qDIAaJQ0UcPi4umKC3+4= Xref: csiph.com comp.lang.java.programmer:31693 On 05/12/2015 10:01 PM, Daniel Pitts wrote: > It occurred to me that I could write this little snippet someplace, and > it would work. > > return stream.filter(o->o<-o); > > stream is an object which implements java.util.stream.BaseStream, though > I won't tell you which one > > Might be obvious to everyone, but I thought it was a good little puzzler. > > What input do you think this will work with, and what is the result? package example; import java.util.Arrays; import java.util.stream.IntStream; public class FilterTest { public static void main(String[] args) { int[] test = new int[]{-2,-1,0,1,2}; filter(test).forEach(p -> System.out.println(p)); } static IntStream filter(int[] t) { IntStream stream = Arrays.stream(t); return stream.filter(o->o<-o); } }