https://kotlinlang.org logo
Title
e

elect

09/25/2021, 6:07 PM
how can you create such a DSL with
+
and
-
operators with implicit receiver?
branchFilter {
                +"refs/heads/my-feature"
            }
c

CLOVIS

09/25/2021, 6:15 PM
The key concepts are: • extension functions • operators can be extension functions • lambdas can be extension functions Now, all you have to do is create a
branchFilter
function that takes a parameter that is lambda with a receiver on some class (eg.
BranchFilterDSL
). Now, all functions declared in
BranchFilterDSL
(or as extensions of
BranchFilterDSL
) are available inside the lambda, and not outside of it.
e

elect

09/25/2021, 6:16 PM
yeah, but as far as I know, you can't use the
+
form unless you have an explicit receiver, ie
receiver + "refs"
ah, it's the
unaryPlus
!
:yes: 1
t

turansky

09/25/2021, 9:31 PM