Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a simple example of inverting @a to a Hash by reversing its keys and values #4561

Open
tbrowder opened this issue Mar 1, 2025 · 3 comments
Labels
docs Documentation issue (primary issue type)

Comments

@tbrowder
Copy link
Member

tbrowder commented Mar 1, 2025

No description provided.

@tbrowder tbrowder added the docs Documentation issue (primary issue type) label Mar 1, 2025
@raiph
Copy link
Contributor

raiph commented Mar 2, 2025

I suggest breaking this existing doc verbiage (from https://docs.raku.org/type/List#routine_invert) where I've inserted a ▲:

Assumes every element of the List is a L<C|/type/Pair>. Returns all elements as a
L<C|/type/Seq> of L<C|/type/Pair>s where the keys and values have been exchanged. ▲ If the value of a L<C|/type/Pair> is an L<C|/type/Iterable>, then it will expand the values
of that L<C|/type/Iterable> into separate pairs.

by inserting this code:

my @a = <list of four strings>;
say @a.pairs.invert.hash; # {list => 0, four => 2, of => 1, strings => 3}

Or perhaps instead add:

my @a = <list of four strings>;
say @a.antipairs.hash; # {list => 0, four => 2, of => 1, strings => 3}

to the antipairs doc?

@tbrowder
Copy link
Member Author

tbrowder commented Mar 2, 2025 via email

@tbrowder
Copy link
Member Author

tbrowder commented Mar 2, 2025

I think the .antipairs method alone is the best way to show the way. Maybe just improve its indexing in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

2 participants