public HashSet<T> appendAll(Iterable<? extends T> it) { HashSet<T> s = this; for(T next : it){ s= s.add(next); } return s; } public <R> R foldLeft(R zero, BiFunction<R, ? super T, R> f){
public HashSet<T> append(T append) { return add(append); }
public HashSet<T> appendAll(Iterable<? extends T> it) { HashSet<T> s = this; for(T next : it){ s= s.add(next); } return s; } public <R> R foldLeft(R zero, BiFunction<R, ? super T, R> f){
public HashSet<T> append(T append) { return add(append); }
@Test public void peek(){ AtomicReference<Vector<Integer>> key = new AtomicReference<>(Vector.empty()); AtomicReference<Vector<Integer>> value = new AtomicReference<>(Vector.empty()); ImmutableMap<Integer,Integer> map = empty(); HashSet<Integer> values = HashSet.empty(); for(int i=0;i<80;i++){ map = map.put(i,i*2); values = values.add(i*2); } ImmutableMap<Integer,Integer> map2 = map.peek(v->value.updateAndGet(vec->vec.append(v))); assertThat(map2.values().toHashSet(),equalTo(values)); }
@Test public void bipeek(){ AtomicReference<Vector<Integer>> key = new AtomicReference<>(Vector.empty()); AtomicReference<Vector<Integer>> value = new AtomicReference<>(Vector.empty()); ImmutableMap<Integer,Integer> map = empty(); HashSet<Integer> keys = HashSet.empty(); HashSet<Integer> values = HashSet.empty(); for(int i=0;i<80;i++){ map = map.put(i,i*2); keys = keys.add(i); values = values.add(i*2); } ImmutableMap<Integer,Integer> map2 = map.bipeek(k->key.updateAndGet(v->v.append(k)), v->value.updateAndGet(vec->vec.append(v))); assertThat(map2.keys().toHashSet(),equalTo(keys)); assertThat(map2.values().toHashSet(),equalTo(values)); } @Test