Skip to content

Commit

Permalink
Merge pull request #241 from Syuparn/add-iterable-t
Browse files Browse the repository at this point in the history
native: impl Arr#T
  • Loading branch information
Syuparn authored Dec 13, 2022
2 parents 8a2ca35 + 3a17e58 commit e79fc6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions native/Arr.pangaea
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
grep: m{|o| @{\ if \ === o}},
# rev returns arr with reversed elements.
rev: m{self[::-1]},
# T returns transposed array of self.
T: m{Arr['zip](*self).A},
# unwrap extracts element if there is only one element.
unwrap: m{self[0] if .len == 1 else self},
}
5 changes: 5 additions & 0 deletions tests/Arr_T_test.pangaea
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assertEq([[1, 2], [3, 4]].T, [[1, 3], [2, 4]])
# length of returned iter is same as the shortest arg
assertEq([[1, 2], [3, 4, 5]].T, [[1, 3], [2, 4]])
# non-array elements can be handled
assertEq(["ab", 2].T, [[?a, 1], [?b, 2]])

0 comments on commit e79fc6b

Please sign in to comment.