@Override public Coll via(def<R> method) { $(iterable) .forEach( e -> { collection.add(method.apply(e)); }); return collection; }
@Override public R[] via(def<R> method) { $(iterable) .forEach( (e, i) -> { if (retArr.length == i.effectiveIndex) { Break(); } else { retArr[i.effectiveIndex] = method.apply(e); } }); return retArr; }
@Override public <Coll extends Collection<T>> Coll findAll(def<Boolean> filter, Coll toColl, int limit) { return $(iterable) .to(toColl) .via( e -> { Boolean ret = filter.apply(e); if (null == ret || ret.equals(false)) Continue(); if (limit > 0 && limit <= toColl.size()) { Break(); } return e; }); }
public <R> R forThose(RFunc1<Boolean, T> predicate, def<R> func) { Iterator<T> it = iterable.iterator(); ptr<Integer> i = ptr(0); IteratorInfo<R> info = new IteratorInfo<R>(); return While( () -> it.hasNext(), (loopInfo) -> { T t = it.next(); try { return If( predicate.apply(t), () -> { return func.apply( t, info.setValues( i.item - 1, i.item + 1, i.item == 0, it.hasNext(), loopInfo.currentIndex, loopInfo.effectiveIndex, loopInfo.lastRes)); }) .Else(() -> null); } catch (Throwable err) { StyleRuntimeException sErr = $(err); Throwable throwable = sErr.origin(); if (throwable instanceof Remove) { it.remove(); } else { throw sErr; } } finally { i.item += 1; } return null; }); }