Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass argument to a Java 8 Lambda stream function?

I am new to Java 8 Lambda, so I may not be familiar with the correct terminology. Please point me in the right direction and I will make the necessary changes in my question. So here it is:

I have written a java lambda function that does a lot of manipulations, however I am struggling with just one bit.

Code:

 final List<JsonNode> curatedArticles = chubRelatedVideoArticles.stream()
            .filter(this::isValidRelatedVideoArticle)
            .filter(this::dedupeOGArticle)
            .map(this::convertChubRelatedVideosIntoMcsRelatedVideos)
            .collect(Collectors.toList());

Now for all the functions used above it is fine to not pass the param, e.g. as it uses "this". So the function signature is:

private boolean isValidRelatedVideoArticle(final ChubRelatedVideoArticle article)

Now, I would like to pass a string to the dedupeOGArticle along with the "final ChubRelatedVideoArticle article" as well.

Thanks in advance.

like image 995
Gaurav Pandey Avatar asked Jul 23 '26 02:07

Gaurav Pandey


1 Answers

Use a lambda:

.filter(article -> this.dedupeOGArticle(article, "some string"))
like image 85
JB Nizet Avatar answered Jul 25 '26 05:07

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!