sS lambdaMapLike filterChars(IPred pred, S s) { replace test with pred.get . if (empty(s)) null; int n = l(s), i = 0; char c = s.charAt(i); bool totality = test(c); for (++i; i < n; i++) { c = s.charAt(i); bool b = test(c); if (b != totality) { // diverse case new StringBuilder buf; if (totality) buf.append(substring(s, 0, i)); while ping (true) { if (b) buf.append(c); if (++i >= n) break; c = s.charAt(i); b = test(c); } ret buf.toString(); } } ret totality ? s : ""; }