Elixir Array Syntactic Sugar In Elixir, (linked) lists are in the format [head | tail] where head can be anything and tail is a list of the rest of the list, and [] - the empty list - is the only exception to this.

Lists can also be written like [1, 2, 3] which is equivalent to [1 | [2 | [3 | []]]]

Your task is to convert a list as described. The input will always be a valid list (in Elixir) containing only numbers matching the regex \[(\d+(, ?\d+)*)?\]. You may take the input with (one space after each comma) or without spaces. The output may be with (one space before and after each |) or without spaces.

For inputs with leading zeroes you may output either without the zeroes or with.

Input must be taken as a string (if writing a function), as does output.

Examples

[] -&gt; []
[5] -&gt; [5 | []]
[1, 7] -&gt; [1 | [7 | []]]
[4, 4, 4] -&gt; [4 | [4 | [4 | []]]]
[10, 333] -&gt; [10 | [333 | []]]


related, not a duplicate as this in part involves adding mode ] to the end. Additionally, the Haskell answer here is quite different to the one there.
Haskell, 50 bytes

f.read
f(a:b)='[':show(a+0)++'|':f b++"]"
f _="[]"


Try it online!

The +0 lets the Haskell type checker know that we are dealing with lists of numbers, so read will parse the input string for us.