Comments (3)
I agree.
If we need to have factory for any schema and required attributes. We may have the following form
type {**required_attrs}
However, KCL currently check the schema type strictly. In the next version, I believe that you can impl the type factory and I will do some minor optimzed changes for KCL and show you the example later. đ
from kcl.
I've opened a PR to impl this: #1269
But I have not added the type
type for the arguments and used a runtime type
type assert statement to verify the argument type at runtime.
schema Foo:
foo: str
schema Bar:
bar: str
factory = lambda type: any, attrs: {:} = {} -> Foo | Bar {
assert typeof(type) == "type"
func = $type
instance = func() {**attrs}
}
_foo = factory(Foo, {foo = "foo"}) # Note we set attributes here.
_bar = factory(Bar, {bar = "bar"}) # Note we set attributes here.
if typeof(_foo) == "Foo":
foo = _foo as Foo
if typeof(_bar) == "Bar":
bar = _bar as Bar
from kcl.
Thanks a lot Peefy! Very solid đ
from kcl.
Related Issues (20)
- Implement Bidirectional Sync between Go Form Rendering and KCL Schema HOT 1
- [Enhancement] Add hover information when input the function argument HOT 1
- Assignments in expressions with square brackets fail HOT 2
- bug in adding to list HOT 1
- [Enhancement] Hover definition not found in the nest schema without the schema name HOT 3
- [Enhancement] Enhance highlighting of nested quotes in long strings. HOT 6
- [Enhancement] Do not upgrade type in the assign statement for the literal type
- Implicit interfaces HOT 2
- kcl run split stderr and stdout ? HOT 2
- Have not get the | - + from """ HOT 2
- Have Repeat run the if conditional . HOT 2
- [BUG] Support configurable PROTOC environment variable with fallback to vendored binaries
- The implicit type specification issue (KCL_FAST_EVAL=1) HOT 1
- Conditional checks on imported resources HOT 1
- argocd kcl plugin rendering is slow and file.modpath is cached by different kcl modules HOT 12
- doc generate error / ć楣çćé误 HOT 4
- When I use attribute as a literal type, the doc generate error. HOT 2
- Enhancement: KCL IDE automatically updates the dependencies through the mod toolchain. HOT 1
- [Enhancement] Enhance the completion experience of KCL Import for both internal and external packages
- How to check dict type in schema HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kcl.