@@ -11,26 +11,27 @@ struct ComplexSpace <: ElementarySpace
1111 d:: Int
1212 dual:: Bool
1313end
14- ComplexSpace (d:: Integer = 0 ; dual = false ) = ComplexSpace (Int (d), dual)
15- function ComplexSpace (dim:: Pair ; dual = false )
16- if dim. first === Trivial ()
17- return ComplexSpace (dim. second; dual = dual)
18- else
19- msg = " $(dim) is not a valid dimension for ComplexSpace"
20- throw (SectorMismatch (msg))
21- end
22- end
23- function ComplexSpace (dims:: AbstractDict ; kwargs... )
24- if length (dims) == 0
25- return ComplexSpace (0 ; kwargs... )
26- elseif length (dims) == 1
27- return ComplexSpace (first (dims); kwargs... )
28- else
29- msg = " $(dims) is not a valid dimension dictionary for ComplexSpace"
30- throw (SectorMismatch (msg))
31- end
14+
15+ ComplexSpace (d:: Integer = 0 ; dual:: Bool = false ) = ComplexSpace (Int (d), dual)
16+ ComplexSpace (dim:: Pair ; kwargs... ) = ComplexSpace ((dim,); kwargs... )
17+ function ComplexSpace (dims; dual:: Bool = false )
18+ # using manual iteration here to avoid depending on `length` while still checking it is
19+ # 0 ≤ length ≤ 1
20+ next = Base. iterate (dims)
21+ isnothing (next) && return ComplexSpace (0 , dual)
22+
23+ (c, d), state = next
24+ convert (Trivial, c) === Trivial () ||
25+ throw (SectorMismatch (lazy " $c is not a valid charge for ComplexSpace" ))
26+
27+ V = ComplexSpace (d, dual)
28+
29+ next = Base. iterate (dims, state)
30+ isnothing (next) ||
31+ throw (SectorMismatch (lazy " $dims is not a valid dimension iterable for ComplexSpace" ))
32+
33+ return V
3234end
33- ComplexSpace (g:: Base.Generator ; kwargs... ) = ComplexSpace (g... ; kwargs... )
3435
3536# convenience constructor
3637Base. getindex (:: ComplexNumbers ) = ComplexSpace
0 commit comments