OpenSearch/docs/painless/painless-lambdas.asciidoc
Jack Conradson d6a4c14e1b
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes.  Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general.  Clean up of all operators sections.  Sporadic clean up else where.
2018-06-07 17:11:56 -07:00

15 lines
603 B
Plaintext

[[painless-lambdas]]
=== Lambdas
Lambda expressions and method references work the same as in https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html[Java].
[source,painless]
---------------------------------------------------------
list.removeIf(item -> item == 2);
list.removeIf((int item) -> item == 2);
list.removeIf((int item) -> { item == 2 });
list.sort((x, y) -> x - y);
list.sort(Integer::compare);
---------------------------------------------------------
You can make method references to functions within the script with `this`,
for example `list.sort(this::mycompare)`.