Skip to content

[Maybe] Incorrect Element requirement for extension on Array for conformance to NodeValueCreatable #57

@balazserdeszlogmein

Description

@balazserdeszlogmein

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]) { [...] }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions