eclipse-collections

2022-08-21 14:27:46 浏览数 (1)

之前分享了vavr,今天在分享一个同类框架eclipse-collections

官方文档:http://www.eclipse.org/collections/

代码语言:javascript复制
<dependency>
  <groupId>org.eclipse.collections</groupId>
  <artifactId>eclipse-collections-api</artifactId>
  <version>11.0.0</version>
</dependency>

<dependency>
  <groupId>org.eclipse.collections</groupId>
  <artifactId>eclipse-collections</artifactId>
  <version>11.0.0</version>
</dependency>

体验下,这是java8 Stream的:

代码语言:javascript复制
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

代码语言:javascript复制
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));

简短了原本的代码

0 人点赞