Add an API for if
with other types than native booleans
#17854
RubenVerg
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Provide a typeclass called something like
If
, taking a single type parameterA
: a condition of the typeA
would call the instanceIf[A].If
orIf[A].IfElse
. This can be used both as a conversion toBoolean
that only works inif
s (eg:) or for a completely unrelated usage to standard
if
, eg in DSLs:This implies that the
if
/else
condition doesn't necessarily return one ofT
orF
, since in this specific usage (the one that led me to the suggestion)igmIfBuild
andigmIfElseBuild
inspect branches to "flatten" if/else clauses into a singleif/else if/else if/else/end
clause (this is an internal to external DSL thing).In the case the condition in the
if
(call itA
) isn'tBoolean
and there is noIf[A]
, try looking for aConversion[A, Boolean]
, and only if it doesn't exist, and there's a singleConversion[A, B]
andIf[B]
, convert toB
.Beta Was this translation helpful? Give feedback.
All reactions