-
Originally opened by @zombiezen in cuelang/cue#484 Is there a convenient way of creating user-defined functions or something similar? Under boilerplate removal, the
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 26 replies
-
Original reply by @zombiezen in cuelang/cue#484 (comment) From @myitcv in Slack: this is the correct way to go for now, but the new evaluator will make this better by allowing non-structs to be emitted. Combined with type cast semantics (like those I proposed in #454), this will make these sorts of limited functions much easier to work with. |
Beta Was this translation helpful? Give feedback.
-
Original reply by @myitcv in cuelang/cue#484 (comment) The current best answer is:
(a change from the previously marked answer because we now have full support for embedded scalars) There is a proposal to support a syntactic sugar based on this:
|
Beta Was this translation helpful? Give feedback.
-
Original reply by @vikstrous2 in cuelang/cue#484 (comment) Taking this idea a step further and adding a conditional:
The conditional version doesn't work with the embedding scalars approach. |
Beta Was this translation helpful? Give feedback.
-
@myitcv is it possible to define functions in go, then import them into cue? I see the builtin-libs use In the interim I'd be satisfied with even just annotating code in go, or if you made the Package construct external. Not sure if this would break any assumptions on the cue runtime, but this could open up making network calls, or other interesting use cases. |
Beta Was this translation helpful? Give feedback.
Original reply by @myitcv in cuelang/cue#484 (comment)
The current best answer is:
(a change from the previously marked answer because we now have full support for embedded scalars)
There is a proposal to support a syntactic sugar based on this: