Skip to content

Swap

Name - Description Default Type
<input> Any input is ignored. Any
<output> The input to this shard is passed through as its output. Any
NameA The name of first variable. "" String&Any
NameB The name of second variable. "" String&Any

Swaps the values of the two variables passed to it via :NameA and :NameB parameters.

Details

Swap swaps the values of the two variables passed to it, one via the :NameA parameter, the other via the :NameB parameter.

This shard works on all kinds of variables and across types. So you can not only swap between two integers, two strings, two sequences, two tables etc., but also between a string and a number, a table and a sequence and so on.

Any input to this shard is ignored and instead passed through as its output.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
"Shards" >= .string
123 >= .number1
456 >= .number2
789 >= .number3
[10 20] >= .sequence
{"k1" 1 "k2" 2} >= .table

(Swap 
    :NameA .number1
    :NameB .number2)        ;; swap two numbers
.number1 (Log "number1")    ;; swapped => number1: 456 
.number2 (Log "number2")    ;; swapped => number2: 123 

(Swap .string .table)       ;; swap a string and a table
.string (Log "string")      ;; swapped => string: {"k1" 1 "k2" 2} 
.table (Log "table")        ;; swapped => table: "Shards" 

(Swap .number3 .sequence)   ;; swap a number and a sequence
.number3 (Log "number3")    ;; swapped => number3:[10 20]
.sequence (Log "sequence")  ;; swapped => sequence: 789
[info] [shards/General/Swap/Swap.edn] number1: 456
[info] [shards/General/Swap/Swap.edn] number2: 123
[info] [shards/General/Swap/Swap.edn] string: {k1: 1 k2: 2}
[info] [shards/General/Swap/Swap.edn] table: Shards
[info] [shards/General/Swap/Swap.edn] number3: [10 20]
[info] [shards/General/Swap/Swap.edn] sequence: 789