Skip to content

Instantly share code, notes, and snippets.

@cgdecker
Created February 15, 2011 16:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgdecker/827748 to your computer and use it in GitHub Desktop.
Save cgdecker/827748 to your computer and use it in GitHub Desktop.
List<Person> people = ...
Iterable<Person> bobs = filter(people, compose(equalTo("Bob"),
Names.GET));
interface HasId {
Long getId();
}
class Ids {
private Ids() {}
public static final Function<HasId, Long> GET =
new Function<HasId, Long>() {
public Long apply(HasId hasId) {
return hasId.getId();
}
};
public static Iterable<Long> of(
Iterable<? extends HasId> items) {
return Iterables.transform(items, GET);
}
}
List<Person> people = ...
for(Long id : Ids.of(people)) { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment