-
Notifications
You must be signed in to change notification settings - Fork 25
[Maybe] Incorrect Element requirement for extension on Array for conformance to NodeValueCreatable #57
Copy link
Copy link
Open
Description
I am looking at the following declarations in NodeArray.swift:
extension Array: NodeValueConvertible, NodeObjectConvertible, NodePropertyConvertible
where Element == NodeValueConvertible {
public func nodeValue() throws -> NodeValue {
let arr = try NodeArray(capacity: count)
for (idx, element) in enumerated() {
try arr[idx].set(to: element)
}
return arr
}
}
extension Array: NodeValueCreatable, AnyNodeValueCreatable where Element == NodeValue {
public static func from(_ value: NodeArray) throws -> [Element] {
try (0..<value.count()).map { try value[$0].nodeValue() }
}
}
Why does the requirement for NodeValueConvertible, NodeObjectConvertible, NodePropertyConvertible requires Element to be less strict, only a NodeValueConvertible - which I can conform to by marking my class as @NodeClass for example - than the requirement for NodeValueCreatable, AnyNodeValueCreatable which requires Element to be a NodeValue, to which a conformance is way harder?
This is problematic, because given this custom type:
@NodeClass
final class MyNodeObjectClass {
[...]
}
I can do this:
@NodeClass
final class MyClass {
@NodeMethod
func myFunc(param: MyNodeObjectClass) { [...] }
}
but I cannot do this:
@NodeClass
final class MyClass {
@NodeMethod
func myFunc(param: [MyNodeObjectClass]) { [...] }
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels