Skip to content

Commit 52f8ad8

Browse files
authored
Merge pull request #377 from d4v1d03/main
added schema lambda support
2 parents 6fddc9c + 182cfae commit 52f8ad8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/user_docs/support/faq-kcl.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,3 +2655,31 @@ If we want to join a given list L = ['a', 'b', 'c'] into a string with some sepe
26552655
S = ",".join(['a', 'b', 'c'])
26562656
```
26572657

2658+
## 66. Is it possible to support schema lambda (class methods) in KCL?
2659+
2660+
KCL supports defining member functions for schemas and can omit them. An example KCL code is shown below for the same:
2661+
2662+
```KCL
2663+
schema Person:
2664+
firstName: str
2665+
lastName: str
2666+
getFullName: () -> str = lambda {
2667+
firstName + " " + lastName
2668+
}
2669+
2670+
p = Person{
2671+
firstName = "Alice"
2672+
lastName = "White"
2673+
}
2674+
fullName = p.getFullName()
2675+
```
2676+
2677+
The above KCL code gives the output:
2678+
2679+
```bash
2680+
p:
2681+
firstName: Alice
2682+
lastName: White
2683+
fullName: Alice White
2684+
```
2685+

0 commit comments

Comments
 (0)