Skip to content

Composition with KeyPath and @dynamicMemberLookup

License

Notifications You must be signed in to change notification settings

acecilia/Compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compose

CI CI

What is this?

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.

Installation

Swift Package Manager

Add the following to the dependencies inside your Package.swift file:

.package(url: "https://github.com/acecilia/Compose.git", .upToNextMajor(from: "0.0.1")),

License

Compose is licensed under the MIT license. See LICENSE for more info.

About

Composition with KeyPath and @dynamicMemberLookup

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages