<~ Assign Or Merge
About 1 min
<~
Assign Or Merge
Merges the right hand value to a variable on the left hand side (expression)
Description
The Assign Or Merge operator merges your data from a the right hand side into the variable on the left hand side.
If the variable doesn't exist, then it is created.
This operator is only available in expressions.
Examples
Appending to an array
Lets say you have a directory hierarchy that looks like:
Β» tree
.
βββ a
β βββ )rPsD8Dt5EtaC4*Yyn0q
β βββ B[E3P2@gyzl2oSfvFs5(
β βββ WNYBb>B{Y:9oBNq~eVn{
β βββ W~e5bLBkGkv 2sr<XTj:
β βββ lgCVRC.PkUkh(!epI(ls
βββ b
β βββ ]^[;og5$x'%Zp* TY(NR
β βββ kKcuV<9@pBrFr@"O\j?%
β βββ wX'\>V`4P=K}FaxE^Hra
β βββ yXjB#Cu'{%iLtsDCkKU%
β βββ |oK7e25Dz7z&ys.?2(]E
βββ c
β βββ )Kb!TOQ]\9J6 &<Y\2qj
β βββ -X-Dm,m[JU0FZ#b0+fe+
β βββ Lw2"`S<ag{EnJ=YI8A\W
β βββ W4RUF_D.z,%M|OFsLB_A
β βββ z@meR3m7h(~V4m7(V{N
βββ d
β βββ %"6Tn]&w@Uas*Gi5$?Q0
β βββ F}Ly:]zGTk}4]V+L=Wk+
β βββ z%;lf^2n0r'p0Fy?f[$j
β βββ {Iz}*#HCR_@H.KyA3=xy
β βββ ~2hUs'_NftfpH`?>Bqpt
βββ e
β βββ :#'G'Rs~^~A)g,k29Er1
β βββ =N-KR9!lh"H FjCp@sP%
β βββ ?,E XTt%TGD4vrvR@qXw
βββ f
βββ !B#v!iYSBmi<i6[mdlL'
βββ _@$*?WgS0KozEnmHV*gW
βββ eT8?OgIK@4zSHTz0$m<O
βββ |c[c-8S.;X$&UzI@jp!X
7 directories, 27 files
...and in this example you want to list the files in only directories that are vowels, you can use the Assign Or Merge operator to append to the list on each iteration for foreach
:
Β» %[a,e] -> foreach d { files <~ g($d/*) }
Β» $files
[
"a/)rPsD8Dt5EtaC4*Yyn0q",
"a/B[E3P2@gyzl2oSfvFs5(",
"a/WNYBb\u003eB{Y:9oBNq~eVn{",
"a/W~e5bLBkGkv 2sr\u003cXTj:",
"a/lgCVRC.PkUkh(!epI(ls",
"e/:#'G'Rs~^~A)g,k29Er1",
"e/=N-KR9!lh\"H FjCp@sP%",
"e/?,E XTt%TGD4vrvR@qXw"
]
Please note that you can also do this with standard globbing, for example:
Β» files = g([ae]/*)
Detail
Assign Or Merge uses the same underlying algorithm as the alter -m
builtin.
See Also
- Alter Data Structure (
alter
/~>
): Change a value within a structured data-type and pass that change along the pipeline without altering the original source input - Expressions (
expr
): Expressions: mathematical, string comparisons, logical operators - For Each In List (
foreach
): Iterate through an array - Globbing (
g
): Glob pattern matching for file system objects (eg*.txt
) - Operators And Tokens: All supported operators and tokens
%[]
Array Builder: Quickly generate arrays
This document was generated from gen/expr/assign-merge-op_doc.yaml.