Skip to content

Conversation

pauljohanneskraft
Copy link
Collaborator

No description provided.


fileprivate func values<Value>(_ compactMap: (Any) -> Value?) -> [Value] {
children.compactMap { compactMap($0.value) }
+ (superclassMirror?.values(compactMap) ?? [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the compactMap closure as it's not a compact map, it's the function that is applied by compact map (but not only!).

Suggestion: mappingFunction or transform.

(I know this code was just moved, but I only noticed it now.)

Also, this is a good example where more code is easier to read:

func values<Value>(_ mappingFunction: (Any) -> Value?) -> [Value] {
    let values = children.compactMap { mappingFunction($0.value) }

    if let superClassValues = superclassMirror?.values(mappingFunction) {
        return values + superClassValues
    } else {
        return values
    }
}

This makes it much more visible when recursion occurs and which is the recursion anchor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also not sure about the function name values but I see where it comes from and I don't have a better idea right now.)


public var content: Any {
guard let value = Mirror(reflecting: self).descendant("storage", "value") else {
assertionFailure("We could not extract a wrappedValue from a Published property wrapper.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who's "we"? 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants