I was trying to learn kotlin and typesafe builders...
# java
m
I was trying to learn kotlin and typesafe builders for kotlin and how we might use them for idiomatic kotlin resource construction
Copy code
managedCluster("cluster-1") {
    args {
        identity {
            type = ResourceIdentityType.SystemAssigned
        }
        servicePrincipalProfile {
            clientId = "msi"
        }
        agentPoolProfiles {
            name   = "pool1"
            count  = 1
            osType = OSType.Linux
            osSKU  = OSSKU.Ubuntu
            vmSize = "standard_a2_v2"
            mode   = AgentPoolMode.System
        }
    }
    opts {
        protect = true
    }
}
It looks like I'm just writing terraform. I'll probably have to modify this to support supplying both
T
and
Output<T>
just thought I'd share.
🎖️ 1
p
That’s cool!
As long as we’re sharing alt-jvm lang code, here’s a snippet from my current project, which I’m currently migrating from ClojureScript (Clojure, but compiles to JavaScript) to Clojure (compiles to Java bytecode):
Copy code
(BucketOwnershipControls. bucket-name
                          (build BucketOwnershipControlsArgs
                                 :bucket (:id bucket)
                                 :rule (build BucketOwnershipControlsRuleArgs
                                              :object-ownership "BucketOwnerEnforced"))
                          (build CustomResourceOptions :parent bucket))
(
build
is a macro I wrote to make using builders more concise.)
m
does clojure have a way to omit the
BucketOwnershipControlsArgs
we were toying with the concept of lambda builders like such:
Copy code
new Profile("blah", pb -> pb
    .resourceGroupName(resourceGroup.getName())
    .location("global")
    .sku(sb -> sb.setName("name")) /// avoid referencing/importing Sku.Builder() since we can bind it in a lambda
);
p
Ah so using reflection to figure out what to build?
Yeah I could probably do that
It's a good idea, I'll give it a try
👍 1
m
well we have control over codegen so we were able to inline it when we were trying it out
p
Probably not necessary with Clojure, since it has macros
m
a very nice advantage.
p
I agree!