Skip to content

Commit 72370e1

Browse files
docs: add docstrings for array conversion
1 parent c1ce4c1 commit 72370e1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ArrayInterface.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,26 @@ ensures_sorted(@nospecialize( T::Type{<:AbstractRange})) = true
10001000
ensures_sorted(T::Type) = is_forwarding_wrapper(T) ? ensures_sorted(parent_type(T)) : false
10011001
ensures_sorted(@nospecialize(x)) = ensures_sorted(typeof(x))
10021002

1003+
"""
1004+
has_trivial_array_constructor(T::Type, args...) -> Bool
1005+
1006+
Returns `true` if an object of type `T` can be constructed using the collection of `args`
1007+
1008+
Note: This checks if a compatible `convert` methood exists between `T` and `args`
1009+
1010+
# Examples:
1011+
1012+
```julia
1013+
julia> ca = ComponentVector((x = rand(3), y = rand(4),))
1014+
ComponentVector{Float64}(x = [0.6549137106381634, 0.37555505280294565, 0.8521039568665254], y = [0.40314196291239024, 0.35484725607638834, 0.6580528978034597, 0.10055508457632167])
1015+
1016+
julia> ArrayInterface.has_trivial_array_constructor(typeof(ca), ones(6))
1017+
true
1018+
1019+
julia> ArrayInterface.has_trivial_array_constructor(typeof(cv), (x = rand(6),))
1020+
false
1021+
```
1022+
"""
10031023
function has_trivial_array_constructor(::Type{T}, args...) where T
10041024
applicable(convert, T, args...)
10051025
end

0 commit comments

Comments
 (0)