use of io.vavr.collection.List in project tutorials by eugenp.
the class CollectionAPIUnitTest method givenParams_whenListAPI_thenCorrect.
@Test
public void givenParams_whenListAPI_thenCorrect() {
List<String> list = List.of("Java", "PHP", "Jquery", "JavaScript", "JShell", "JAVA");
List list1 = list.drop(2);
assertFalse(list1.contains("Java") && list1.contains("PHP"));
List list2 = list.dropRight(2);
assertFalse(list2.contains("JAVA") && list2.contains("JShell"));
List list3 = list.dropUntil(s -> s.contains("Shell"));
assertEquals(list3.size(), 2);
List list4 = list.dropWhile(s -> s.length() > 0);
assertTrue(list4.isEmpty());
List list5 = list.take(1);
assertEquals(list5.single(), "Java");
List list6 = list.takeRight(1);
assertEquals(list6.single(), "JAVA");
List list7 = list.takeUntil(s -> s.length() > 6);
assertEquals(list7.size(), 3);
List list8 = list.distinctBy((s1, s2) -> s1.startsWith(s2.charAt(0) + "") ? 0 : 1);
assertEquals(list8.size(), 2);
Iterator<List<String>> iterator = list.grouped(2);
assertEquals(iterator.head().size(), 2);
Map<Boolean, List<String>> map = list.groupBy(e -> e.startsWith("J"));
assertEquals(map.size(), 2);
assertEquals(map.get(false).get().size(), 1);
assertEquals(map.get(true).get().size(), 5);
String words = List.of("Boys", "Girls").intersperse("and").reduce((s1, s2) -> s1.concat(" " + s2)).trim();
assertEquals(words, "Boys and Girls");
}
use of io.vavr.collection.List in project tutorials by eugenp.
the class CollectionAPIUnitTest method givenEmptyList_whenStackAPI_thenCorrect.
@Test
public void givenEmptyList_whenStackAPI_thenCorrect() {
List<Integer> intList = List.empty();
List<Integer> intList1 = intList.pushAll(List.rangeClosed(5, 10));
assertEquals(intList1.peek(), Integer.valueOf(10));
List intList2 = intList1.pop();
assertEquals(intList2.size(), (intList1.size() - 1));
}
Aggregations