Duplicate an endpoint config, then apply a partial timeout update to it.
← Operators and Expressions · Ref: Q1079
Copy all fields, then merge a partial update:
copied :=: original target :~: patch
:=: copies ALL fields (set and unset). :~: copies only SET fields, leaving unset fields in the target unchanged.
See Q1075 for copy details. See Q1077 for merge details.
Example
defines module qa.operators.copyvsmergereplace defines class Endpoint url <- String() timeout <- Integer() retries <- Integer() Endpoint() -> url as String timeout as Integer retries as Integer this.url :=: url this.timeout :=: timeout this.retries :=: retries //Constructor for partial updates — only timeout Endpoint() -> timeout as Integer this.timeout :=: timeout operator :~: -> from as Endpoint if from.url? url :=: from.url if from.timeout? timeout :=: from.timeout if from.retries? retries :=: from.retries default operator ? default operator $ default operator :=: defines program CopyVsMergeReplaceDemo() stdout <- Stdout() original <- Endpoint("https://api.example.com", 30, 3) // :=: COPY — exact duplicate of all fields copied <- Endpoint() copied :=: original stdout.println(`Copy: ${copied}`) // :~: MERGE — only the set timeout field is applied patch <- Endpoint(60) target <- Endpoint("https://old.example.com", 10, 1) stdout.println(`Before merge: ${target}`) target :~: patch stdout.println(`After merge: ${target}`)
Other ways to ask this
- I need to back up a config with :=: then patch one field using :~:
- In Python I'd copy then dict.update(). Write the EK9 equivalent with :=: and :~:
- Given an Endpoint, create an exact copy then merge in a timeout-only change
- Copy all fields from one record, then merge only the set fields from a patch
Coming from another language?
Java: no distinction — clone() copies all. Python: copy vs dict.update(). Go: struct assignment vs manual field merge. EK9: :=: (duplicate all) vs :~: (patch set fields only).
Keywords: :~:, comparison, merge, partial update, copy, difference, :=: