Skip to content

Instantly share code, notes, and snippets.

Map<Color, Long> map =
people.stream().collect(Collectors.groupingBy(
Person::getFavoriteColor,
Collectors.counting()));
Map<Color, List<Person>> map = people
.stream()
.collect(Collectors.groupingBy(Person::getFavoriteColor));
Map<Color, Set<Person>> map =
people.stream().collect(Collectors.groupingBy(
Person::getFavoriteColor,
Collectors.toSet()));
MutableSetMultimap<Color, Person> multimap =
people.groupBy(Person::getFavoriteColor);
MutableSet<Address> addresses = people.collect(Person::getAddress);
MutableSet<Person> people = ...;
MutableSet<Address> addresses = people
.asLazy()
.collect(Person::getAddress)
.toSet();
Set<Person> people = ...;
Set<Address> addresses = people
.stream()
.map(Person::getAddress)
.collect(Collectors.toSet());
@motlin
motlin / BottomType.java
Created June 12, 2012 02:59
Code example to illustrate bottom types
public Option<V> get(Object key)
{
V result = this.table.get(key);
if (result == null && !this.table.containsKey(key))
{
return None.INSTANCE;
}
return new Some<V>(result);
}
@motlin
motlin / BottomType.java
Created June 12, 2012 02:55
Code example to illustrate bottom types
public enum None implements Option<Nothing>
{
INSTANCE;
public Nothing get()
{
throw new UnsupportedOperationException("None.get()");
}
}
@motlin
motlin / BottomType.hs
Created June 6, 2012 03:08
Code example to illustrate bottom types
undefined :: a
error :: [Char] -> a