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.init(_:error:using:) #128

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

Add: Fallible.init(_:error:using:) #128

oscbyspro opened this issue Nov 12, 2024 · 2 comments
Labels
addition oh, so shiny! 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
@oscbyspro
Copy link
Owner Author

Having thought about this for some time, I'm leaning in the other direction. I'm not convinced that this is a problem that needs solving. Similarly, the static Fallible.sink(_:) method has not been used much and could be removed. Hm.

@oscbyspro oscbyspro added no don't even think about it and removed maybe to do, or not to do? labels Nov 29, 2024
@oscbyspro oscbyspro closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
@oscbyspro oscbyspro added maybe to do, or not to do? and removed no don't even think about it labels Nov 29, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Nov 30, 2024

I'm working on a mini Fallible<T> rework and this version is perhaps convenient enough:

extension Fallible {
    @inlinable public init<Error>(
        _ value: consuming Value,
        error: consuming Bool = false,
        using  setup: (inout Value, inout Bool) throws(Error) -> Void
    )   throws(Error)
}

@oscbyspro oscbyspro reopened this Nov 30, 2024
@oscbyspro oscbyspro added this to the Ultimathnum 0.12.0 milestone Nov 30, 2024
@oscbyspro oscbyspro removed the brrr such code, much wow label Nov 30, 2024
@oscbyspro oscbyspro changed the title Add: Fallible.sink(_:performing:) Add: Fallible.init(_:error:using:) Nov 30, 2024
@oscbyspro oscbyspro added maybe to do, or not to do? and removed maybe to do, or not to do? labels Nov 30, 2024
@oscbyspro oscbyspro removed this from the Ultimathnum 0.12.0 milestone Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! maybe to do, or not to do?
Projects
None yet
Development

No branches or pull requests

1 participant