Skip to content

flatmap description is wrong #851

@smls

Description

@smls

https://docs.perl6.org/type/List#method_flatmap incorrectly suggests that flatmap flattenes the input list before iterating it, when in fact it seems to flatten the result of the map operation:

dd ((1, 2), <a b>).map({ $_, $_ });      # (((1, 2), (1, 2)), (("a", "b"), ("a", "b"))).Seq
dd ((1, 2), <a b>).flatmap({ $_, $_ });  # (1, 2, 1, 2, "a", "b", "a", "b").Seq

The example given on the page should be removed altogether, as it lies about &uc being called four times (it's called twice, once for each element of the input list), and doesn't produce a nested output so there's nothing to flatten, and thus fails to demonstrate what flatmap actually does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation issue (primary issue type)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions