@@ -141,31 +141,21 @@ end
141
141
argtail (x, rest... ) = rest
142
142
tail (x:: Tuple ) = argtail (x... )
143
143
144
- # TODO : a better / more infer-able definition would pehaps be
145
- # tuple_type_head(T::Type) = fieldtype(T::Type{<:Tuple}, 1)
146
- tuple_type_head (T:: UnionAll ) = (@_pure_meta ; UnionAll (T. var, tuple_type_head (T. body)))
147
- function tuple_type_head (T:: Union )
148
- @_pure_meta
149
- return Union{tuple_type_head (T. a), tuple_type_head (T. b)}
150
- end
151
- function tuple_type_head (T:: DataType )
152
- @_pure_meta
153
- T. name === Tuple. name || throw (MethodError (tuple_type_head, (T,)))
154
- return unwrapva (T. parameters[1 ])
155
- end
144
+ tuple_type_head (T:: Type ) = (@_pure_meta ; fieldtype (T:: Type{<:Tuple} , 1 ))
156
145
157
- tuple_type_tail (T:: UnionAll ) = (@_pure_meta ; UnionAll (T. var, tuple_type_tail (T. body)))
158
- function tuple_type_tail (T:: Union )
146
+ function tuple_type_tail (T:: Type )
159
147
@_pure_meta
160
- return Union{tuple_type_tail (T. a), tuple_type_tail (T. b)}
161
- end
162
- function tuple_type_tail (T:: DataType )
163
- @_pure_meta
164
- T. name === Tuple. name || throw (MethodError (tuple_type_tail, (T,)))
165
- if isvatuple (T) && length (T. parameters) == 1
166
- return T
148
+ if isa (T, UnionAll)
149
+ return UnionAll (T. var, tuple_type_tail (T. body))
150
+ elseif isa (T, Union)
151
+ return Union{tuple_type_tail (T. a), tuple_type_tail (T. b)}
152
+ else
153
+ T. name === Tuple. name || throw (MethodError (tuple_type_tail, (T,)))
154
+ if isvatuple (T) && length (T. parameters) == 1
155
+ return T
156
+ end
157
+ return Tuple{argtail (T. parameters... )... }
167
158
end
168
- return Tuple{argtail (T. parameters... )... }
169
159
end
170
160
171
161
tuple_type_cons (:: Type , :: Type{Union{}} ) = Union{}
0 commit comments