We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I wonder if the following could be of use, @jsbean ?
struct Prism <A,B> { let unwrap: (A) -> B? let wrap: (B) -> A } enum Music { static var objects: [Music] = [] case duration(Duration) case pitch(Pitch) ... } extension Music { enum prism { static let duration = Prism<Music, Duration>( unwrap: { if case let .duration(object) = $0 { return object } return nil }, wrap: Music.duration ) static let pitch = Prism<Music, Pitch>( unwrap: { if case let .pitch(object) = $0 { return object } return nil }, wrap: Music.pitch ) } ... } extension Music { func allDurations() -> [Duration] { return Music.objects.compactMap(Music.prism.duration.unwrap) } func allPitches() -> [Pitch] { return Music.objects.compactMap(Music.prism.pitch.unwrap) } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I wonder if the following could be of use, @jsbean ?
The text was updated successfully, but these errors were encountered: