Skip to content

Commit

Permalink
simplify the internal conjoin/disjoin MaybeError operations
Browse files Browse the repository at this point in the history
  • Loading branch information
veigaribo committed Oct 16, 2020
1 parent 995a358 commit 2349df5
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,30 @@ export class MaybeError extends Maybe<string> {
// error + error -> error
// error + not error -> error
// not error + not error -> not error
conjoin(error: MaybeError) {
if (this.isError()) {
if (error.isError()) {
return new MaybeError(MaybeError.appendText(this.value!, error.value!))
conjoin(other: MaybeError) {
if (other.isError()) {
if (this.isError()) {
return new MaybeError(MaybeError.appendText(this.value!, other.value!))
} else {
return this
return other
}
} else {
if (error.isError()) {
return error
} else {
// whatever
return this
}
return this
}
}

// error + error -> error
// error + not error -> not error
// not error + not error -> not error
disjoin(error: MaybeError) {
if (this.isSuccess()) {
return this
} else {
if (error.isSuccess()) {
return error
disjoin(other: MaybeError) {
if (other.isError()) {
if (this.isError()) {
return new MaybeError(MaybeError.appendText(this.value!, other.value!))
} else {
return new MaybeError(MaybeError.appendText(this.value!, error.value!))
return this
}
} else {
return other
}
}

Expand Down

0 comments on commit 2349df5

Please sign in to comment.