Replies: 1 comment 1 reply
-
So you have two unrelated modules, but you want to express a constraint between those two? The most straightforward solution is to define a property that you then fill in later. Then, you'd define a constraint in terms of that property, for example: BaseClass.pkl import "OtherModule.pkl"
hidden myOtherModule: OtherModule
class BaseClassWithMultipleFieldsToOverride {
name: String
tags: Listing<String>?
}
the_config: Listing<
BaseClassWithMultipleFieldsToOverride(
tags.every((tag) ->
myOtherModule
.the_other_collection
.any((it) -> tag.startsWith(it)
)
)
)
> Then at your usage site: // base_class.pkl amends ".../BaseClass.pkl"
myOtherModule = import("other_module.pkl")
the_config {
new {
name = "Name"
tags {
"a"
}
}
} One restriction here is that you have to define the constraint on a module property, rather than a class property (because class properties can only see |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello
I was wondering if it's possible to have a type constraint evaluate lazily, while having a base structure where some fields of base class, or a module, are overridden further down a file hierarchy.
Here's an example which works, but the type constraint definition has to be repeated for each overriding file.
BaseClass.pkl
OtherModule.pkl
overrides/other_module.pkl
overrides/overriding_base_class.pkl
Which evaluates to
But, I'd want to define the constraint only once, in
BaseClass.pkl
and then have the overriding module, hereoverrides/overriding_base_class.pkl
, evaluate that constraint using the definition ofthe_other_collection
, fromimport "other_module.pkl" as O
.Is there a language feature I'm missing? Thank you.
Beta Was this translation helpful? Give feedback.
All reactions