Skip to content

Short circuit the and/or operators#65

Merged
cdhoffmann merged 5 commits intoadobe:dev-v1.2.3from
cdhoffmann:shortCircuitAndOr
Apr 12, 2023
Merged

Short circuit the and/or operators#65
cdhoffmann merged 5 commits intoadobe:dev-v1.2.3from
cdhoffmann:shortCircuitAndOr

Conversation

@cdhoffmann
Copy link
Copy Markdown
Contributor

@cdhoffmann cdhoffmann commented Apr 11, 2023

#63 This is an optimization to our And/Or operators where

  1. For "And" we fail early without evaluating other conditions
  2. For "Or" we succeed early without evaluating other conditions

@cdhoffmann cdhoffmann requested a review from praveek April 11, 2023 21:39
@cdhoffmann cdhoffmann linked an issue Apr 11, 2023 that may be closed by this pull request
operandsResults.append(result)
}
return Result.failure(.innerFailures(message: "`Or` returns false", errors: operandsResolve.filter { !$0.value }.map { $0.error ?? RulesFailure.unknown }))
return Result.failure(.innerFailures(message: "`Or` returns false", errors: operandsResults.filter { !$0.value }.map { $0.error ?? RulesFailure.unknown }))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can remove the filter operation as operandsResults contains only failures.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lmk if that looks better

@cdhoffmann cdhoffmann requested a review from praveek April 12, 2023 14:57
@cdhoffmann cdhoffmann merged commit f838918 into adobe:dev-v1.2.3 Apr 12, 2023
@cdhoffmann cdhoffmann deleted the shortCircuitAndOr branch April 12, 2023 19:26
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

Successfully merging this pull request may close these issues.

Short circuiting logical operators in rules engine

2 participants