Created
February 15, 2011 16:26
-
-
Save cgdecker/827748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Person> people = ... | |
Iterable<Person> bobs = filter(people, compose(equalTo("Bob"), | |
Names.GET)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface HasId { | |
Long getId(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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