yegor256 / cactoos

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons
https://www.cactoos.org
MIT License
735 stars 164 forks source link

org.cactoos.arrays.Mapped #1631

Closed yegor256 closed 2 years ago

yegor256 commented 2 years ago

How about a new package for manipulations with arrays? A Mapped one would be useful, and others too.

victornoel commented 2 years ago

@yegor256 there are no "array" interface and an array is everything but an object, while in cactoos, the main OO abstraction for manipulating data such as collections, array, etc is Iterable which is lazy by nature.

The classes in that package should be enough to map over an array, you will end up with an Iterable, and if you want to materialize it into an array, the recommend approach is to pass it then to ListOf onto which you can call toArray like so:

int[] arr = { 1, 2, 3 }
new org.cactoos.list.ListOf(
  new org.cactoos.iterable.Mapped(e -> e*2, arr)
).toArray(int[]::new);
yegor256 commented 2 years ago

@victornoel got it, thanks