Can it be implemented as a dsl tho?
# stdlib
a
Can it be implemented as a dsl tho?
g
You cannot implement exactly the same syntax in DSL, but of course you can create some DSL that would do the same what when does, but without some advanced features like smartcast or exhaustiveness
a
Do u have an example of how to make a simpler when?
g
What is your use case?
In general just add multiple lambdas with expression to some block
🤔 1
a
Curiosity really - I want to write some nice dsls that are more than just builders of objects - I want them to be conditionals and do stuff based on those conditions
I don’t follow
r
I have zero idea of what are you trying to do, but here's random when-style DSL for you: https://pl.kotl.in/S1vp92JO4 It's eager, without
else
branch, without exiting on first match, without ability to return the value, but still a basic example where one could start.
âž• 1
a
Oh thanks
That’s what i was looking for
r
When over type comparisons is just fold
Chaining Boolean predicates in order is filter
Over an ADT expressed as sealed classes
a
Yes i know
r
Then that is the DSL over Boolean conditions just add them as verbs expressed as classes
m
Here is my `when`ish DSL, which uses
then
instead of
->
. https://github.com/Miha-x64/Flawless/