A Swift library for composing structs from other structs, which relies on the KeyPath
and @dynamicMemberLookup
features to provide a clean and typesafe API:
import Compose
struct Developer: Codable, Hashable {
var name: String
var age: Int
}
struct RemoteLocation: Codable, Hashable {
var country: String
var city: String
}
typealias RemoteDeveloper = Compose<Developer, RemoteLocation>
let remoteDeveloper = RemoteDeveloper(
.init(name: "Andres", age: 26),
.init(country: "Spain", city: "Madrid")
)
print(remoteDeveloper.name) // Andres
print(remoteDeveloper.city) // Madrid
For an in depth explanation please follow this link.
Add the following to the dependencies inside your Package.swift
file:
.package(url: "https://github.com/acecilia/Compose.git", .upToNextMajor(from: "0.0.1")),
Compose is licensed under the MIT license. See LICENSE for more info.