Skip to content
New issue

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

[Duration] Implement more type-safe Rhythm.Leaf.Kind.Collection and Builder #75

Open
jsbean opened this issue Sep 8, 2018 · 0 comments

Comments

@jsbean
Copy link
Member

jsbean commented Sep 8, 2018

There is currently no way of ensuring that a .continuation(...) does not succeed an .absence.

Perhaps a good way to deal with this is similar to the Path.Builder.

extension Rhythm.Leaf.Kind {
    struct Collection { }
}
protocol AllowingStart { 
    func start(_ attack: Element) -> AllowingStart & AllowingContinuation & AllowingAbsence
    func start(_ attack: Element, _ release: Element) -> AllowingStart & AllowingAbsence
}
protocol AllowingContinuation { 
    func continuation(_ sustain: Element) -> AllowingStart & AllowingContinuation & AllowingAbsence
    // if a release element is provided, don't allow continuation
    func continuation(_ sustain: Element, _ release: Element) -> AllowingStart & AllowingAbsence
}
protocol AllowingAbsence { 
    // don't allow continuation after rest
    func absence() -> AllowingStart & AllowingAbsence
}
extension Rhythm.Leaf.Kind.Collection {
    final class Builder { 
         var storage: [Leaf.Kind] = []
    }
}
extension Rhythm.Leaf.Kind.Collection.Builder: 
    AllowingStart, 
    AllowingContinuation,
    AllowingAbsence 
{
    ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant