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

Array->rotate #146

Open
schwern opened this issue Jul 8, 2010 · 5 comments
Open

Array->rotate #146

schwern opened this issue Jul 8, 2010 · 5 comments

Comments

@schwern
Copy link
Contributor

schwern commented Jul 8, 2010

Thinking of an array of strings as rows and columns, flip the columns and rows. So:

my @rows = ("AAA", "BBB", "123");
my @columns = @rows->rotate;  # ("AB1", "AB2", "AB3");

Short rows are filled in with spaces, possible configurable option.

my @rows = ("A", "BBB", "1234");
my @columns = @rows->rotate;  # ("AB1", " B2", " B3", "  4");

See http://stackoverflow.com/questions/3206720/perl-hash-of-hash-and-columns/3206871#3206871 for inspiration.

@schwern
Copy link
Contributor Author

schwern commented Jul 8, 2010

Would Array->transpose be a better name? Should rotate/transpose work on a 2d array and make array-of-strings rotation into something else?

@Daenyth
Copy link

Daenyth commented Jul 8, 2010

+1 for transpose acting on a 2d array. I don't think it makes much sense to have a built in function like this that acts on a 1d array.

@exodist
Copy link
Contributor

exodist commented Jul 8, 2010

I also say +1 for transpose acting on a 2d array.

As for 1 dimensional, I think it may be more time than it is worth, but otherwise am not apposed. needs a new name though @rows->transpose_text

@hercynium
Copy link

I agree that transpose is better than rotate, simply because I think of rotation as just that: put the elements on a wheel and spin $x degrees.

When I think of transposition on an array, I definitely think of it in the mathematical sense, requiring at least a 2D matrix. Therefore, calling the operation you've described above "transpose" just doesn't quite seem right. However, @exodist's suggestion of transpose_text seems to strike the right balance - The semantics that it is special because the contents are text is much more clear.

tl;dr: +1 for transpose_text on a 1d array of text. +1 for transpose on 2d arrays of anything.

@burak
Copy link

burak commented Nov 1, 2011

Hmmm, is there a practical use case for this?

notbenh pushed a commit to notbenh/perl5i that referenced this issue Mar 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants