Created
November 13, 2022 08:34
-
-
Save TsRebornz/409ae56f7349624d32fad86b2dd03e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Size { | |
var width: Int | |
let height: Int | |
} | |
enum Material: String { | |
case wood | |
case iron | |
} | |
struct Table { | |
var size: Size | |
let material: Material | |
} | |
extension Table { | |
var isWood: Bool { | |
return material == .wood | |
} | |
} | |
let tables: [Table] = [ | |
.init( | |
size: .init(width: 150, height: 10), | |
material: .iron | |
), | |
.init( | |
size: .init(width: 200, height: 10), | |
material: .iron | |
), | |
.init( | |
size: .init(width: 100, height: 10), | |
material: .wood | |
) | |
] | |
// Mapping | |
let tableMaterials = tables.map(\.material) | |
// Filtering | |
let woodTables = tables.filter(\.isWood) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment