Documentation for method flatmap
Documentation for method flatmap, assembled from the following types:
method flatmap(Any: --> Seq)
Any as 1-item list and uses
List.flatmap on it.
say Any.flatmap(); # OUTPUT: «((Any))␤»
method flatmap(List: --> Seq)
map iterates over the elements of the invocant list, feeding each element in turn to the code reference, and assembling the return values from these invocations in a result list.
The use of
flatmap is strongly discouraged. Instead of
.flatmap( ), please use
.map( ).flat as it is clear when the
.flat is called and is not confusing like
map it flattens non-itemized lists and arrays, so
## flatmapmy = ('first1', ('second2', ('third3', 'third4'), 'second5'), 'first6');say .flatmap().perl;# OUTPUT «("first1", "second5", "third3", "third4", "second2", "first6").Seq␤»## mapsay .map().perl;# OUTPUT «("first1 was a Str", "second2 third3 third4 second5 was a List", "first6 was a Str").Seq␤»## .map .flat has the same output as .flatmapsay .map().flat.perl# OUTPUT «("first1", "second5", "third3", "third4", "second2", "first6").Seq␤»