@@ -238,30 +238,55 @@ public function mapTo(callable $mapper, self $stream): static
238238 }
239239
240240 /**
241- * @param callable(array|mixed): array{string,mixed} $func
241+ * Mapping values to MapStream
242+ *
243+ * @param callable(array|mixed): array{string,mixed} $mapper
242244 * @param MapStream|null $new
243245 *
244246 * @return MapStream
245247 */
246- public function mapToMap (callable $ func , MapStream $ new = null ): MapStream
248+ public function mapToMap (callable $ mapper , MapStream $ new = null ): MapStream
247249 {
248250 $ new = $ new ?: new MapStream ();
249251 foreach ($ this as $ item ) {
250- [$ key , $ val ] = $ func ($ item );
252+ [$ key , $ val ] = $ mapper ($ item );
251253 $ new ->offsetSet ($ key , $ val );
252254 }
253255
254256 return $ new ;
255257 }
256258
257259 /**
260+ * Mapping values to IntStream
261+ *
262+ * @param callable(T):int $mapper
263+ * @param IntStream|null $new
264+ *
265+ * @return IntStream
266+ */
267+ public function mapToInt (callable $ mapper , IntStream $ new = null ): IntStream
268+ {
269+ $ new = $ new ?: new IntStream ;
270+ foreach ($ this as $ val ) {
271+ $ new ->append ($ mapper ($ val ));
272+ }
273+
274+ return $ new ;
275+ }
276+
277+ /**
278+ * Mapping values to StringStream
279+ *
280+ * @param callable(T):string $mapper
281+ * @param StringStream|null $new
282+ *
258283 * @return StringStream
259284 */
260- public function mapToString (): StringStream
285+ public function mapToString (callable $ mapper , StringStream $ new = null ): StringStream
261286 {
262- $ new = new StringStream ;
287+ $ new = $ new ?: new StringStream ;
263288 foreach ($ this as $ val ) {
264- $ new ->append ($ val );
289+ $ new ->append ($ mapper ( $ val) );
265290 }
266291
267292 return $ new ;
@@ -534,6 +559,12 @@ public function eachToMap(callable $func, array $map = []): array
534559 return $ map ;
535560 }
536561
562+ /**
563+ * @param callable $handler
564+ * @param ...$args
565+ *
566+ * @return mixed
567+ */
537568 public function collect (callable $ handler , ...$ args ): mixed
538569 {
539570 // TODO
0 commit comments