@@ -11,7 +11,7 @@ const Base = parentmodule(@__MODULE__)
1111using . Base:
1212 @inline , Pair, Pairs, AbstractDict, IndexLinear, IndexStyle, AbstractVector, Vector,
1313 SizeUnknown, HasLength, HasShape, IsInfinite, EltypeUnknown, HasEltype, OneTo,
14- @propagate_inbounds , @isdefined , @boundscheck , @inbounds , Generator,
14+ @propagate_inbounds , @isdefined , @boundscheck , @inbounds , Generator, IdDict,
1515 AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
1616 (:), | , + , - , * , != = , ! , == , != , <= , < , > , >= , missing ,
1717 any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
@@ -1547,7 +1547,9 @@ Stacktrace:
15471547[...]
15481548```
15491549"""
1550- @propagate_inbounds function only (x)
1550+ @propagate_inbounds only (x) = _only (x, iterate)
1551+
1552+ @propagate_inbounds function _only (x, :: typeof (iterate))
15511553 i = iterate (x)
15521554 @boundscheck if i === nothing
15531555 throw (ArgumentError (" Collection is empty, must contain exactly 1 element" ))
@@ -1559,6 +1561,15 @@ Stacktrace:
15591561 return ret
15601562end
15611563
1564+ @inline function _only (x, :: typeof (first))
1565+ @boundscheck if length (x) != 1
1566+ throw (ArgumentError (" Collection must contain exactly 1 element" ))
1567+ end
1568+ @inbounds first (x)
1569+ end
1570+
1571+ @propagate_inbounds only (x:: IdDict ) = _only (x, first)
1572+
15621573# Specific error messages for tuples and named tuples
15631574only (x:: Tuple{Any} ) = x[1 ]
15641575only (x:: Tuple ) = throw (
0 commit comments