@Test
    public void testGroupBy() {
        Map<Integer, List<Integer>> map1 = Seq.of(1, 2, 3, 4).groupBy(i -> i % 2);
        assertEquals(asList(2, 4), map1.get(0));
        assertEquals(asList(1, 3), map1.get(1));
        assertEquals(2, map1.size());

        Map<Integer, List<Tuple2<Integer, Integer>>> map2 =
        Seq.of(tuple(1, 1), tuple(1, 2), tuple(1, 3), tuple(2, 1), tuple(2, 2))
           .groupBy(t -> t.v1);
        assertEquals(asList(tuple(1, 1), tuple(1, 2), tuple(1, 3)), map2.get(1));
        assertEquals(asList(tuple(2, 1), tuple(2, 2)), map2.get(2));

        Map<Integer, Long> map3 =
        Seq.of(tuple(1, 1), tuple(1, 2), tuple(1, 3), tuple(2, 1), tuple(2, 2))
           .groupBy(t -> t.v1, counting());
        assertEquals(3L, (long) map3.get(1));
        assertEquals(2L, (long) map3.get(2));

        Map<Integer, Tuple2<Long, String>> map4 =
        Seq.of(tuple(1, 1), tuple(1, 2), tuple(1, 3), tuple(2, 4), tuple(2, 5))
           .groupBy(t -> t.v1, collectors(counting(), mapping(t -> t.map2(Object::toString).v2, joining(", "))));
        assertEquals(3L, (long) map4.get(1).v1);
        assertEquals(2L, (long) map4.get(2).v1);
        assertEquals("1, 2, 3", map4.get(1).v2);
        assertEquals("4, 5", map4.get(2).v2);
    }
@author Lukas Eder
@author Roman Tkalenko
jOOL/src/test/java/org/jooq/lambda/SeqTest.java