Skip to content

added schema lambda support #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2655,3 +2655,31 @@ If we want to join a given list L = ['a', 'b', 'c'] into a string with some sepe
S = ",".join(['a', 'b', 'c'])
```

## 66. Is it possible to support schema lambda (class methods) in KCL?

KCL supports defining member functions for schemas and can omit them. An example KCL code is shown below for the same:

```KCL
schema Person:
firstName: str
lastName: str
getFullName: () -> str = lambda {
firstName + " " + lastName
}

p = Person{
firstName = "Alice"
lastName = "White"
}
fullName = p.getFullName()
```

The above KCL code gives the output:

```bash
p:
firstName: Alice
lastName: White
fullName: Alice White
```

Loading