Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Last active December 19, 2016 14:35
Show Gist options
  • Select an option

  • Save sliskiCode/170867dab3a9ee8da85801dd84c0a065 to your computer and use it in GitHub Desktop.

Select an option

Save sliskiCode/170867dab3a9ee8da85801dd84c0a065 to your computer and use it in GitHub Desktop.
Living (Android) without Kotlin #11
import lombok.Data;
import lombok.experimental.ExtensionMethod;
@ExtensionMethod(Streams.class)
public class Foo {
void foo(List<Person> persons) {
persons.toStream()
.filter(it -> it.getAge() >= 21)
.filter(it -> it.getName().startsWith("P"))
.map(Person::getName)
.sorted()
.forEach(System.out::println);
}
}
@Data class Person {
final String name;
final int age;
}
class Streams {
static <T> Stream<T> toStream(List<T> list) {
return Stream.of(list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment