@Test public void iterableStream() { ReactiveSeq<String> res = For.iterable(new MyIterable()).yield(v -> v + "*").unwrap(); List<String> expected = Arrays.asList("hello*", "world*"); assertThat(expected, equalTo(res.toList())); }
@Test public void arrayStream() { List<String> res = For.stream(Stream.of("hello world", "hello")).yield(v1 -> v1 + "1").stream().toList(); List<String> expected = Arrays.asList("hello world1", "hello1"); assertThat(expected, equalTo(res)); }
@Test public void mapStream() { Map<String, Integer> m = new HashMap<>(); m.put("hello", 10); List<String> res = For.stream(m.entrySet().stream()).yield(v -> "" + v + "*").stream().toList(); List<String> expected = Arrays.asList("hello=10*"); assertThat(expected, equalTo(res)); }
@Test public void stringStreamWithNull() { Stream<String> res = For.stream("hello world".chars().boxed().map(i -> Character.toChars(i)[0])) .iterable(i -> (Iterable<String>) null) .yield(v1 -> v2 -> "" + v1 + v2) .unwrap(); List<String> expected = Arrays.asList(); assertThat(expected, equalTo(res.collect(Collectors.toList()))); }
@Test public void stringStream() { List<String> res = For.stream("hello world".chars().boxed().map(i -> Character.toChars(i)[0])) .yield(v -> "" + v + "1") .<String>stream() .toList(); List<String> expected = Arrays.asList("h1", "e1", "l1", "l1", "o1", " 1", "w1", "o1", "r1", "l1", "d1"); assertThat(expected, equalTo(res)); }