File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
src/Fp/Functions/Collection Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,25 @@ function filterNotNull(iterable $collection): array
112112 */
113113function filterMap (iterable $ collection , callable $ predicate ): array
114114{
115- $ gen = FilterMapOperation::of ($ collection )(dropFirstArg ($ predicate ));
115+ return filterMapKV ($ collection , dropFirstArg ($ predicate ));
116+ }
117+
118+ /**
119+ * Same as {@see filterMap()} but passing also the key to the $predicate function.
120+ *
121+ * @template TK of array-key
122+ * @template TV
123+ * @template TVO
124+ *
125+ * @param iterable<TK, TV> $collection
126+ * @param callable(TK, TV): Option<TVO> $predicate
127+ * @return array<TK, TVO>
128+ *
129+ * @psalm-return ($collection is list<TV> ? list<TVO> : array<TK, TVO>)
130+ */
131+ function filterMapKV (iterable $ collection , callable $ predicate ): array
132+ {
133+ $ gen = FilterMapOperation::of ($ collection )($ predicate );
116134
117135 return is_array ($ collection ) && array_is_list ($ collection )
118136 ? asList ($ gen )
You can’t perform that action at this time.
0 commit comments