|
1 | 1 | /* |
2 | 2 | * The MIT License (MIT) |
3 | 3 | * |
4 | | - * Copyright 2015-2020 Valentyn Kolesnikov |
| 4 | + * Copyright 2015-2021 Valentyn Kolesnikov |
5 | 5 | * |
6 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 | * of this software and associated documentation files (the "Software"), to deal |
@@ -156,7 +156,8 @@ public String apply(Map<K, V> value) { |
156 | 156 | final String escape = TEMPLATE_SETTINGS.get(ESCAPE); |
157 | 157 | String result = template; |
158 | 158 | for (final Map.Entry<K, V> element : value.entrySet()) { |
159 | | - final String value1 = String.valueOf(element.getValue()).replace("\\", "\\\\"); |
| 159 | + final String value1 = String.valueOf(element.getValue()).replace("\\", "\\\\") |
| 160 | + .replace("$", "\\$"); |
160 | 161 | result = java.util.regex.Pattern.compile(interpolate.replace(ALL_SYMBOLS, |
161 | 162 | S_Q + element.getKey() |
162 | 163 | + E_S)).matcher(result).replaceAll(value1); |
@@ -317,6 +318,16 @@ public static <T, E> List<T> map(final List<E> list, final Function<? super E, T |
317 | 318 | return transformed; |
318 | 319 | } |
319 | 320 |
|
| 321 | + public static <T, E> List<T> mapMulti(final List<E> list, |
| 322 | + final BiConsumer<? super E, ? super Consumer<T>> mapper) { |
| 323 | + final List<T> transformed = newArrayListWithExpectedSize(list.size()); |
| 324 | + for (E element : list) { |
| 325 | + Consumer<T> value = t -> transformed.add(t); |
| 326 | + mapper.accept(element, value); |
| 327 | + } |
| 328 | + return transformed; |
| 329 | + } |
| 330 | + |
320 | 331 | public <F> List<F> map(final Function<? super T, F> func) { |
321 | 332 | return map(newArrayList(iterable), func); |
322 | 333 | } |
@@ -2745,6 +2756,10 @@ public <F> Chain<F> map(final Function<? super T, F> func) { |
2745 | 2756 | return new Chain<>(U.map(list, func)); |
2746 | 2757 | } |
2747 | 2758 |
|
| 2759 | + public <F> Chain<F> mapMulti(final BiConsumer<? super T, ? super Consumer<F>> mapper) { |
| 2760 | + return new Chain<>(U.mapMulti(list, mapper)); |
| 2761 | + } |
| 2762 | + |
2748 | 2763 | public <F> Chain<F> mapIndexed(final BiFunction<Integer, ? super T, F> func) { |
2749 | 2764 | return new Chain<>(U.mapIndexed(list, func)); |
2750 | 2765 | } |
|
0 commit comments