Coder Social home page Coder Social logo

Comments (3)

marksands avatar marksands commented on May 21, 2024 1

That's super interesting, thanks for the tip! The accompanying bugs.swift.org post has a lot of good info on that as well. I'll spend some time digging into these nuances and see what I can come up with.

from bettercodable.

marksands avatar marksands commented on May 21, 2024 1

@Stevenmagdy Appreciate the offer but no thanks. I'm still on the fence with supporting something similar to KeyedContainer. There are a lot of bugs-used-as-features in regards to Dictionary de/en/coding right now so I've been hoping to see Swift make a decision here or tell us this is the bed we must lie in.

from bettercodable.

StevenSorial avatar StevenSorial commented on May 21, 2024

@Strobocop I have this extension in my code

extension KeyedDecodingContainer {
  func decodeRawKeyedDict<K: RawRepresentable, V: Decodable>(
    _ type: [K: V].Type,
    forKey key: Key
  ) throws -> [K: V] where K.RawValue: Decodable & Hashable {
    let rawDict = try decode([K.RawValue: V].self, forKey: key)
    let tupleArray = rawDict.compactMap { key, value in
      K(rawValue: key).flatMap { ($0, value) }
    }
    return .init(tupleArray) { first, second in first }
  }
}

@marksands Open for a PR?

from bettercodable.

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.