java
2022-07-06
2022-07-06
志向和热爱是伟大行为的双翼。——歌德
之前分享了vavr,今天在分享一个同类框架eclipse-collections
官方文档:http://www.eclipse.org/collections/
1 |
|
体验下,这是java8 Stream
的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
boolean anyPeopleHaveCats =
this.people
.stream()
.anyMatch(person -> person.hasPet(PetType.CAT));
long countPeopleWithCats =
this.people
.stream()
.filter(person -> person.hasPet(PetType.CAT))
.count();
List<Person> peopleWithCats =
this.people
.stream()
.filter(person -> person.hasPet(PetType.CAT))
.collect(Collectors.toList());
用eclipse-collections
:
1
2
3
4
5
6
7
8
9
10
11
boolean anyPeopleHaveCats =
this.people
.anySatisfy(person -> person.hasPet(PetType.CAT));
int countPeopleWithCats =
this.people
.count(person -> person.hasPet(PetType.CAT));
MutableList<Person> peopleWithCats =
this.people
.select(person -> person.hasPet(PetType.CAT));
简短了原本的代码