Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Google Guava (Java), why are Iterables.getFirst() and getLast() inconsistent? [duplicate]

Tags:

From Google Guava JavaDoc for Iterables:

static <T> T getFirst(Iterable<T> iterable, T defaultValue) 

-> Returns the first element in iterable or defaultValue if the iterable is empty.

static <T> T getLast(Iterable<T> iterable) 

-> Returns the last element of iterable.

static <T> T getLast(Iterable<T> iterable, T defaultValue) 

-> Returns the last element of iterable or defaultValue if the iterable is empty.

One static method is missing (to me):

static <T> T getFirst(Iterable<T> iterable) 

-> Returns the first element of iterable.

Do you know the reason for this inconsistency?

like image 481
kevinarpe Avatar asked Oct 20 '11 07:10

kevinarpe


1 Answers

Because it's too simple to justify a helper method. The method would just be iterable.iterator().next() and would have behavior exactly analogous to getLast().

like image 149
Sean Owen Avatar answered Sep 18 '22 13:09

Sean Owen