Coder Social home page Coder Social logo

Comments (11)

tonyd256 avatar tonyd256 commented on May 24, 2024

Haha, this is a very big model. I can see why you're hitting the limits of Swift's currying. Are there some submodels you feel you can make of these? A couple ideas I have are:

All the keys starting with "total" can be moved into a Totals model.
All of the "spells" can be moved into a Spells model.
All of the "items" can be moved into a ItemStorage model.

And in a similar fashion, group as many like things as you can into separate models. This might make things easier to work with too.

Another idea, if you are displaying all of these attributes to a user on some UI, maybe you can group these properties by the UI portion they will be displayed on. Say for instance you have a UI that has different views for the items the user had and a different view for the spells they used. Then you could group those into separate models. When it comes time to display the info, you can hand each view only the model it needs to display its information.

from argo.

czeluff avatar czeluff commented on May 24, 2024

Yep, that's one plan of attack. You could also make a case for having a struct that simply alphabetizes the properties: statsAF (all stats with variables names A-F), statsGM, etc.

The other plan: make RawStats only contain one 'let': the raw json itself, which can be extracted from a JSON enum via a switch statement. In decode, make a RawStats struct with one property, then wrap it in Decoded, and return it.

Then have all of the rest of these pieces of data - item0, item1, etc - be computed properties that simply get the value out of the JSON when requested. Yes, it moves very far away from what Argo is trying to accomplish with the Decoded type, the safety, the error messages, the guarantees of data existence, etc. But this is the only piece of data that has this issue, and I'm fine waiting for this Swift issue to go away.

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

Ya, I think your second option isn't a bad idea for this. Unfortunately, Swift just can't handle so many properties on a model just yet. If you have a model that just contains the raw JSON value then you can make computed properties like you said. You can even use Argo in the computed properties to just get that one value out of the JSON.

from argo.

samritchie avatar samritchie commented on May 24, 2024

In my testing the limit seems to be around 10-12 properties, which I don’t think is excessive on a model. The workaround from Swift 1.1 is broken on 1.2, and I’m struggling to work out what’s going on with the types.

Calling MyType.create <^> j <| "property1" <*> j <| "property2" returns a Decoded<(remainder of curried create function)> (e.g. Decoded<(property3: String) -> MyType>)

If I assign this to a local variable, based on my limited understanding of applicatives, I should be able to continue in a new expression with: f <*> j <| "property3", however this doesn’t type check: Could not find an overload for '<*>' that accepts the supplied arguments

I’m not sure if my understanding is correct, or I’ve missed something obvious. At the moment I’m manually running the logic from apply, i.e.:

    switch f {
    case let .Success(box):
        return box.value <^> j <| "property3"
    case let .MissingKey(string):
        return .MissingKey(string)
    case let .TypeMismatch(string):
        return .TypeMismatch(string)
    }

but this is really clunky and there must be an easier way.

from argo.

tonyd256 avatar tonyd256 commented on May 24, 2024

@samritchie Thank you for bringing this to our attention. This issue seems to have started when switching to the Decoded type. This is most likely a bug with the compiler as we can reproduce this with Array but not with Optional. We'll be submitting a bug to Apple for this.

In the mean time, we found a workaround. If you add _ to your curried parameters it should work. For instance:

static func create(prop1: String)(prop2: String)(_ prop3: String) -> String {
  return ""
}

let f = MyType.create <^> j <| "property1" <*> j <| "property2"
let x = f <*> j <| "property3"

Hope this helps. Going to keep this open for now. Please feel free to ask more questions about this workaround. @gfontenot is submitting a radar as we speak and will post the ID in here when he's done.

from argo.

samritchie avatar samritchie commented on May 24, 2024

Thanks, that works. That was an odd one - I’m relieved to know I haven’t misunderstood applicatives as much as I thought.

from argo.

gfontenot avatar gfontenot commented on May 24, 2024

The radar I submitted is available on Open Radar. The Swift team doesn't like dupes, so no point in that, but it's been reported.

from argo.

nvkv avatar nvkv commented on May 24, 2024

Looks like workaround with _ in curried parameters has limited functionality.

Update: It works like a charm and I should go to sleep next time I intend to write in this thread.

I have a create function like this:

public static func create(id: String?)
        (title: String?)
        (address: String?)
        (_ description: String?)
        (_ area: Double?)
        (_ price: Price?)
        (_ roomsNumber: Int?)
        (_ photoIds: [String]?)
        (_ contacts: [String]?) -> Realty 

And decode function:

    public static func decode(x: JSON) -> Decoded<J>? {
        let partial = Realty.create
            <^> x <|? "id"
            <*> x <|? "title"
            <*> x <|? "address"

        let partial2 = partial
            <*> x <|? "description"
            <*> x <|? "area"
            <*> x <|? "price"

        return partial2
            <*> x <|? "roomsNumber"
            <*> x <|? "photoIds"
            <*> x <|? "contacts"
    }

And on last partial clause I'm getting Could not find an overload for '<*>' that accepts the supplied arguments error.

from argo.

gfontenot avatar gfontenot commented on May 24, 2024

@semka the last two lines of your parser are parsing single values where your create function expects arrays. Replace those two with <||? and you should be good to go.

from argo.

nvkv avatar nvkv commented on May 24, 2024

Me so stupid, thank you very much!

from argo.

gfontenot avatar gfontenot commented on May 24, 2024

I'm going to go ahead and close this. Feel free to continue to talk in here.

from argo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.