Local storage in a stream Java 8 -


i want write stream method may need ignore several concurrent values based on "lastgoodversion" can't find way share value within stream. below i'd do. suggestions on how accomplish this?

[edit don't this, it's not how java streams work]

i don't think possible using java 8 streams. possible solution want use helper function may this:

private static <t> stream<t> progressivefilter(stream<t> stream,                                                bipredicate<t, t> predicate) {     list<t> list = stream.collect(collectors.tolist());     list<t> result = new arraylist<>();     t previousvalue = null;     (t entry : list) {         if (previousvalue == null) {             previousvalue = entry;         } else {             if (predicate.test(entry, previousvalue)) {                 result.add(previousvalue);             } else {                 previousvalue = entry;             }         }     }     if(previousvalue != null) {         result.add(previousvalue);     }     return result.stream(); } 

the call trying this:

progressivefilter(     allversionsstream().filter(nstimestamp::isapproved),     (v, lastcanonicalversion) -> !v.iseffectivebefore(relativedate)                                && v.iseffectivebefore(lastcanonicalversion)); 

quite possibly can further optimized. principle, hope, clear.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -