Java implenetations of
list()
and head()
.
3fef209b49
Bumps [junit-jupiter](https://github.com/junit-team/junit5) from 5.6.1 to 5.6.2. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.6.1...r5.6.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> |
||
---|---|---|
.github | ||
src | ||
.gitignore | ||
LICENSE | ||
pom.xml | ||
README.md |
List Head/Tail
Provides a head()
and tail()
implementation for List<>
objects in Java.
Usage
import net.kemitix.list.HeadTail;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class Usage {
List<String> list = Arrays.asList("a", "b", "c");
Optional<String> head = HeadTail.head(list); // head()
assertThat(head).contains("a");
List<String> tail = HeadTail.tail(list); // tail()
assertThat(tail).containsExactly("b", "c");
}
Statically importing the head()
and tail()
methods will be more
readable and idiomatically FP.
import static net.kemitix.list.HeadTail.*;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class Usage {
List<String> list = Arrays.asList("a", "b", "c");
Optional<String> head = head(list); // head()
assertThat(head).contains("a");
List<String> tail = tail(list); // tail()
assertThat(tail).containsExactly("b", "c");
}