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

Add: Fallible.sink(_:performing:) #128

Open
oscbyspro opened this issue Nov 12, 2024 · 0 comments
Open

Add: Fallible.sink(_:performing:) #128

oscbyspro opened this issue Nov 12, 2024 · 0 comments
Labels
addition oh, so shiny! brrr such code, much wow maybe to do, or not to do?

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Nov 12, 2024

I stumbled upon this ceremony while working on composable (#126) algorithms:

func algorithm<T>(_ value: consuming T) -> Fallible<T> {
    var error: Bool = false
    
    value = foo(value).sink(&error)
    value = bar(value).sink(&error)
    value = baz(value).sink(&error)

    return Fallible(value, error: error)
}

It isn't terrible, but a Fallible.sink(_:performing:) is perhaps more ergonomic:

func algorithm<T>(_ value: consuming T) -> Fallible<T> {
    Fallible.sink(consume  value) { 
        value,  error in
        value = foo(value).sink(&error)
        value = bar(value).sink(&error)
        value = baz(value).sink(&error)
    }
}
@oscbyspro oscbyspro added addition oh, so shiny! brrr such code, much wow maybe to do, or not to do? labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! brrr such code, much wow maybe to do, or not to do?
Projects
None yet
Development

No branches or pull requests

1 participant