Back to articles
Tsonnet #33 - The arithmetic tutorial must go on
How-ToTools

Tsonnet #33 - The arithmetic tutorial must go on

via Dev.toHercules Lemke Merscher

Welcome to the Tsonnet series! If you're not following along, check out how it all started in the first post of the series . In the previous post, we added a full set of binary operators: Tsonnet #32 - != done, but getting there Hercules Lemke Merscher ・ Mar 5 #tsonnet #jsonnet #compiler We were almost done with the arithmetic tutorial . Two pieces were still missing: object merging, and division by zero error handling. Let's wrap those up. Merging objects The + operator is overloaded to act as an operator to merge two objects. This sample file: // samples/objects/merge.jsonnet { a : 1 , b : 2 } + { b : 3 , c : 4 } Results in: { "a" : 1 , "b" : 3 , "c" : 4 } The right-hand side overrides the left-hand side fields. The cram test looks like this: diff --git a/test/cram/objects.t b/test/cram/objects.t index 9c12260..bfb25bd 100644 --- a/test/cram/objects.t +++ b/test/cram/objects.t @@ -18,3 +18,6 @@ $ tsonnet ../../samples/objects/toplevel_field_lookup_chain.jsonnet { "answer": { "value":

Continue reading on Dev.to

Opens in a new tab

Read Full Article
5 views

Related Articles