Search code examples
j

How to unbox a list of boxed lists of differing lengths in J?


Given the following list of boxed lists of differing lengths…

┌──────────────┬───────────┬─────┬───┐
│0 2 3 4 7 9 11│9 7 4 3 2 1│1 2 3│3 1│
└──────────────┴───────────┴─────┴───┘

How can I create a single list like so:

0 2 3 4 7 9 11 9 7 4 3 2 1 1 2 3 3 1

Every time I try this I get trailing zeros. I understand why that happens, but it's not what I want.


Solution

  • Use raze (;)

    [a =: (0 2 3 4 7 9 11);(9 7 4 3 2 1);(1 2 3);(3 1)
    ┌──────────────┬───────────┬─────┬───┐
    │0 2 3 4 7 9 11│9 7 4 3 2 1│1 2 3│3 1│
    └──────────────┴───────────┴─────┴───┘
    ;a
    0 2 3 4 7 9 11 9 7 4 3 2 1 1 2 3 3 1
    

    Raze "assembles along a leading axis the opened elements of the ravel of y" so its use case is exactly what you want.