[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding marshaled() to Array<Marshaling> #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adding marshaled() to Array<Marshaling> #104

wants to merge 1 commit into from

Conversation

pepasflo
Copy link

Hey! Thanks for writing Marshal.

Consider these nested types:

struct Person {
    let name: String
}

struct Group {
    let name: String
    let members: [Person]
}

I'm guessing the implementation of Marshaling on Group.members would look like this?

extension Person: Marshaling {
    func marshaled() -> [String: Any] {
        return ["name": self.name]
    }
}

extension Group: Marshaling {
    func marshaled() -> [String: Any] {
        return [
            "name": name,
            "members": self.members.map { $0.marshaled() }
        ]
    }
}

Is that the expected way to do that, or did I miss something obvious?

This PR adds Marshaling on Array<Marshaling>, so that you can do this instead:

extension Group: Marshaling {
    func marshaled() -> [String: Any] {
        return [
            "name": name,
            "members": self.members.marshaled()
        ]
    }
}

@jarsen
Copy link
Member
jarsen commented Mar 22, 2017

Hey! Yeah, using map would be the correct way to do that.

As to the addition, I think that looks great. Let us mull it over for a day or two though. Recently we've had a lot of great contributions but Marshal has really started to grow beyond it's original simple and small state. Let's get some discussion @bwhiteley what do you think? I think this is a good addition.

@jarsen
Copy link
Member
jarsen commented Mar 28, 2017

Hey @pepasflo. I'm good to merge this. Would you be willing to write up a few tests?

@pepasflo
Copy link
Author

@jarsen sure, good idea! I'll get this done within the next few days.

@gaming-hacker
Copy link

Did this get merged?

@JetForMe
Copy link
Contributor
JetForMe commented Jan 9, 2023

I'd like to see this merged, too!

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.

4 participants