-
Notifications
You must be signed in to change notification settings - Fork 464
Add destructuring declarations for Either and Ior #3831
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
base: main
Are you sure you want to change the base?
Conversation
|
|
…nents Includes build configuration change to allow contracts on operators.
|
To be honest, I don't think this fits the style we want to promote in Arrow. What are your use cases and why doesn't using a Also, note that using |
|
I can't share my exact use-case unfortunately, however our main focus isn't really on The main point on adding it to Use Case: Resilient Parsing / Success with WarningsWhen using Current StateTo simply log the errors and use the data, we have to handle all 3 branches ( result.fold(
{ err -> logger.warn(err) },
{ data -> process(data) },
{ err, data ->
logger.warn(err)
process(data)
}
)This boilerplate might look acceptable at first glance, but as logic grows, this approach creates an unavoidable pyramid of doom. DestructuringThe descructuring approach fits the semantic of "inclusive or" perfectly I think because it allows independent handling of the independent axes. val (problems, value) = docParser.parse(input)
if (problems != null) {
logger.warn("Parsing issues found: $problems")
}
if (value != null) {
process(value)
}This flattens the control flow and decouples the error handling from the success handling, which is exactly what Regarding
|
|
You should have a look at the |
|
Yeah we're already using Anyway I understand all your concerns and if you decide against this. |
|
It'd be great to hear what shortfalls you find with |
|
I still see this as a no-go for the current API design of Arrow. Although there may be situations where this may help, making this part of the library brings a lot of potential for misuse. A few pointer, though. I don't see how your example gets much worse with matching: val result = docParser.parse(input)
if (result is Left) {
logger.warn("Parsing issues found: ${result.value}")
}
if (value is Right) {
process(result.value)
}In fact, for val result = docParser.parse(input).onLeft {
logger.warn("Parsing issues found: ${result.value}")
} |
|
Either is a union type. I think we should not treat it as a product type. |
This adds the possibility to destruct
EitherandIorlike in go:Unfortunately I can't run
apiDumpbecause it can't find the task andbuildas it fails with the following error:However any maintainer can quickly jump in run and commit these in this PR.