StarWarsArrays.jl
Introduction
StarWarsArrays.jl
is a Julia package to provide
arrays indexed as the order of the Star Wars movies. Thus, index 4 points to
the first element of the parent array, index 2 points to its fifth element, and
index 9 points to the nineth element. The ordering applies to all dimensions of
the array. StarWarsArrays.jl
also supports Machete
Order.
This package is inspired by the Reddit thread "Oof level of an array, nice.".
Installation
The latest version of StarWarsArrays.jl
is available for Julia v1.0 and
later releases, and can be installed with Julia's built-in package
manager. In a Julia session, after
entering the package manager mode with ]
, run the command
pkg> add https://github.com/giordano/StarWarsArrays.jl
Usage
julia> using StarWarsArrays
julia> v = StarWarsArray(collect(1:9))
9-element StarWarsArray{Int64,1,Array{Int64,1},StarWarsArrays.OriginalOrder}:
4
5
6
1
2
3
7
8
9
julia> v[4]
1
julia> v[2]
5
julia> v[9]
9
julia> v[5] = 42
42
julia> v
9-element StarWarsArray{Int64,1,Array{Int64,1},StarWarsArrays.OriginalOrder}:
4
5
6
1
42
3
7
8
9
julia> m = StarWarsArray(reshape(collect(1:81), 9, 9))
9ร9 StarWarsArray{Int64,2,Array{Int64,2},StarWarsArrays.OriginalOrder}:
31 40 49 4 13 22 58 67 76
32 41 50 5 14 23 59 68 77
33 42 51 6 15 24 60 69 78
28 37 46 1 10 19 55 64 73
29 38 47 2 11 20 56 65 74
30 39 48 3 12 21 57 66 75
34 43 52 7 16 25 61 70 79
35 44 53 8 17 26 62 71 80
36 45 54 9 18 27 63 72 81
julia> m[5]
2
julia> m[5,1]
29
julia> m[5,4]
2
julia> m[5,8]
65
julia> m[3,2] = -1
-1
julia> m
9ร9 StarWarsArray{Int64,2,Array{Int64,2},StarWarsArrays.OriginalOrder}:
31 40 49 4 13 22 58 67 76
32 41 50 5 14 23 59 68 77
33 -1 51 6 15 24 60 69 78
28 37 46 1 10 19 55 64 73
29 38 47 2 11 20 56 65 74
30 39 48 3 12 21 57 66 75
34 43 52 7 16 25 61 70 79
35 44 53 8 17 26 62 71 80
36 45 54 9 18 27 63 72 81
The second argument of StarWarsArray
allows you to specify the order. Here is how to
use MacheteOrder
:
julia> using StarWarsArrays
julia> v = StarWarsArray(collect(1:9), MacheteOrder)
8-element view(::Array{Int64,1}, [3, 4, 1, 2, 5, 6, 7, 8]) with eltype Int64:
3
4
1
2
5
6
7
8
julia> v[4]
1
julia> v[3]
4
julia> v[1]
ERROR: StarWarsError: there is no episode 1 in order MacheteOrder
[...]
julia> m = StarWarsArray(reshape(collect(1:81), 9, 9), MacheteOrder)
8ร8 view(::Array{Int64,2}, [3, 4, 1, 2, 5, 6, 7, 8], [3, 4, 1, 2, 5, 6, 7, 8]) with eltype Int64:
21 30 3 12 39 48 57 66
22 31 4 13 40 49 58 67
19 28 1 10 37 46 55 64
20 29 2 11 38 47 56 65
23 32 5 14 41 50 59 68
24 33 6 15 42 51 60 69
25 34 7 16 43 52 61 70
26 35 8 17 44 53 62 71
julia> m[5,4]
2
julia> m[2,9]
66
julia> m[1,6]
ERROR: StarWarsError: there is no episode 1 in MacheteOrder
[...]
License
The StarWarsArrays.jl
package is licensed under the MIT "Expat" License. The
original author is Mosรจ Giordano.
Disclaimer
Star Wars is the sole and exclusive property of Lucasfilm Limited.
StarWarsArrays.jl
is in no way affiliated with or endorsed by Lucasfilm
Limited or any of its subsidiaries, employees, or
associates. StarWarsArrays.jl
offers no suggestion that the work presented on
this web page is "official" or produced or sanctioned by the owner or any
licensees of the aforementioned trademark.