Data-structure

Index

All Data-structure functions

The data-structure functions are divided into list functions and map functions.

Name Function header Example Result Description Errorhandling
append func(list interface{}, v interface{}) []interface{} [[ $result := push $result "AfterD" ]] $result = [A B C D AfterD] adds an item onto the end of a list
dict func(v …interface{}) map[string]interface{} [[ $result := dict "field1" "This is a test string" ]] $result = map[field1:This is a test string] returns a map with key value pairs.
first func(list interface{}) interface{} [[ $result := first (list "field1" "field2") ]] $result = field1 returns the first item on a list.
has func(haystack interface{}, needle interface{}) bool [[ $result := has (list "A" "B" "C") "B" ]] $result = true Test to see if a list has a particular element.
initial func(item interface{}) []interface{} [[ $result := initial ( list "A" "B" "C" ) ]] $result = [A B] returns all items from a list without the last item.
keys func(dicts …map[string]interface{}) []string [[ $result := keys ( dict "F2" "B" "F3" "C" ) ]] $result = [F2 F3] returns all keys from a map
last func(list interface{}) interface{} [[ $result := last ( list "A" "B" "C" ) ]] $result = C returns the last item from a list.
list func(v …interface{}) []interface{} [[ $result := list 1 2 3 4 ]] $result = [1 2 3 4] provides a simple list type that can contain arbitrary sequential lists of data.
listContains func(haystack interface{}, needle interface{}) bool [[ $result := has (list "A" "B" "C") "B" ]] $result = true Test to see if a list has a particular element.
mapSet func(d map[string]interface{}, key string, value interface{}) map[string]interface{} [[ $result := mapSet $map "F4" "D" ]] $result = map[F1:A F4:D] defines a map based on a key and a value.
mapUnset func(d map[string]interface{}, key string) map[string]interface{} [[ $result := mapUnset $result "fieldinteger2" ]] $result = map[] removes a map/key value pair in a mapset.
merge func(dst map[string]interface{}, srcs …map[string]interface{}) interface{} [[ $result := merge $map1 $map2 ]] $result = map[firstName:Max lastName:Muster] merges 2 maps to 1 map.
mergeOverwrite func(dst map[string]interface{}, srcs …map[string]interface{}) (interface{}, error) [[ $result := mergeOverwrite $map30 $map31 ]] $result = map[lastName:Huber] overwrites a map based on the key. X
omit func(dict map[string]interface{}, keys …string) map[string]interface{} [[ $result := omit $map "F1" "F3" ]] $result = map[F2:B] is similar to pick, except it returns a new dict with all the keys that do not match the given keys.
pick func(dict map[string]interface{}, keys …string) map[string]interface{} [[ $result := pick $map "F2" ]] $result = map[F2:B] selects just the given keys out of a dictionary, creating a new dict.
pluck func(key string, d …map[string]interface{}) []interface{} [[ $result := pluck "F2" $map ]] $result = [B] makes it possible to give one key and multiple maps, and get a list of all of the matches.
prepend func(list interface{}, v interface{}) []interface{} [[ $result := prepend $list "BeforeA" ]] $result = [BeforeA A B C D] adds an item onto the beginning of a list.
push func(list interface{}, v interface{}) []interface{} [[ $result := push $result "AfterD" ]] $result = [A B C D AfterD] adds an item onto the end of a list
rest func(list interface{}) []interface{} [[ $result := rest ( list 1 2 3 4 ) ]] $result = [2 3 4] get the tail of the list (everything but the first item).
reverse func(v interface{}) []interface{} [[ $result := reverse ( list 1 2 3 4 ) ]] $result = “[4 3 2 1]” Produce a new list with the reversed elements of the given list.
slice func(list interface{}, indices …interface{}) interface{} [[ $result := slice ( list 1 2 3 4 5 ) 1 4 ]] $result = [2 3 4] cuts/slices a list
uniq func(list interface{}) []interface{} [[ $result := uniq ( list 1 1 2 2 )]] $result = [2 3] contains only unique list entries.
values func(dict map[string]interface{}) []interface{} [[ $result := values ( mapSet ( dict "F1" "A" ) "F4" "D" ) ]] $result = [A D] contains an array with all the values of the map.
without func(list interface{}, omit …interface{}) []interface{} [[ $result := without ( list 1 2 3 4 ) 3 ]] $result = [1 2 4] filters items out of a list.

append

see function description push

dict

func(v ...interface{}) map[string]interface{}

The dict function returns a map with key value pairs.

Examples


[[ $result := dict "field1" "This is a test string" ]]
$result = map[field1:This is a test string]

[[ $result := dict "field1" "This is a test string" "field2" "Test string 2" ]]
$result = map[field1:This is a test string field2:Test string 2]

[[ dict "field1" "This is a test string" "fieldinteger2" 999 ]]
$result = map[field1:This is a test string fieldinteger2:999]

first

func(list interface{}) interface{}

The first function returns the first item on a list.

Examples


[[ $result := first (list "field1" "This is a test string" "field2" "Test string 2")  ]]
$result = field1

[[ $result := first (list "This is a test string" "field1" "field2" "Test string 2")  ]]
$result = This is a test string

has

func(haystack interface{}, needle interface{}) bool

The has function tests a list, if it has a particular element. It needs an exact match.

Application notes / Limits:

  • Alias-Name: listContains

Examples


[[ $result := has ( list "A" "B" "C" ) "B" ]]
$result = true

[[ $result := has ( list "A" "B" "C" ) "Z" ]]
$result = false

initial

func(item interface{}) []interface{}

The initial function returns all items from a list without the last item.

Examples


[[ $result := initial ( list "A" "B" "C" ) ]]
$result = [A B]

keys

func(dicts ...map[string]interface{}) []string

The keys function returns all keys from a map

Examples


[[ $result := keys ( dict "F2" "B" "F3" "C" ) ]]
$result = [F2 F3]

last

func(list interface{}) interface{}

The last function returns the last item from a list.

Examples


[[ $result := last ( list "A" "B" "C" ) ]]
$result = C

list

// TODO Jira-Task 499 https://itdistrict.atlassian.net/jira/software/projects/ING/boards/3/backlog?selectedIssue=ING-499

func(v ...interface{}) []interface{}

The list function provides a simple list type that can contain arbitrary sequential lists of data. This is similar to arrays or slices, but lists are designed to be used as immutable data types.

Examples


[[ $result := list "This is a test string" "ing" ]]
$result = [This is a test string ing]

[[ $result := list 1 2 3 4 ]]
$result = [1 2 3 4]

listContains

see function description has

mapSet

func(d map[string]interface{}, key string, value interface{}) map[string]interface{}

The mapSet function defines a map based on a key and a value.

Application notes / Limits:

  • $map must be a valid map-object. You can do this with function dict, splitToMap or newData
  • Description to the example:
    • “firstName” = field name
    • “Max” = value of the field “firstName”

Examples


[[ $result    := dict "F1" "A" ]]
[[ $result    := mapSet $map "F4" "D" ]]
$result = map[F1:A F4:D]

[[ $map    := mapSet $map "firstName" "Max" ]]
[[ $map    := mapSet $map "lastName" "Muster" ]]
$result = map[firstName:Max lastName:Muster]

mapUnset

func(d map[string]interface{}, key string) map[string]interface{}

The mapUnset function removes a map/key value pair in a mapset.

Examples


[[ $result := mapUnset $result "fieldinteger2"  ]]
$result = map[]

complex example with dict, mapSet and mapUnset command
[[ $map := dict "F1" "A" ]]
[[ $map := mapSet $map "F2" "B" ]]
[[ $result := mapUnset $map "F2" ]]
$result = map[F1:A]

merge

func(dst map[string]interface{}, srcs ...map[string]interface{}) interface{}

The merge function merges 2 maps to 1 map.

Examples


[[ $result := indent "This is a test string" 5 ]]
$result = "     This is a test string"

[[ $map1   := dict "firstName" "Max" ]]
[[ $map2   := dict "lastName" "Muster" ]]
[[ $result := merge $map1 $map2 ]]
$result = map[firstName:Max lastName:Muster]

complex example with dict, mapSet and mapUnset command
[[ $map3   := dict "2ndFristName" "Willhelm" ]]
[[ $result := merge $map1 $map2 $map3 ]]
$result = map[2ndFristName:Willhelm firstName:Max lastName:Muster]

mergeOverwrite

func(dst map[string]interface{}, srcs ...map[string]interface{}) (interface{}, error)

The mergeOverwrite function overwrites a map based on the key.

Examples


[[ $map30   := dict "lastName" "Meier" ]]
[[ $map31   := dict "lastName" "Huber" ]]
[[ $result  := mergeOverwrite $map30 $map31 ]]
$result = map[lastName:Huber]

omit

func(dict map[string]interface{}, keys ...string) map[string]interface{}

The omit function is similar to pick, except it returns a new dict with all the keys that do not match the given keys.

Examples


[[ $map := dict "F1" "A" "F2" "B" "F3" "C" ]]
[[ $result := omit $map "F1" "F3" ]]
$result = map[F2:B]

complex example with dict, mapSet and omit command
[[ $map := newMap  ]]
[[ $map := dict "F1" "A" "F3" "C" ]]
[[ $map  = mapSet $map "F4" "D" ]]
[[ $map  = mapSet $map "F5" "Z" ]]
[[ $map  = mapSet $map "F2" "B" ]]
[[ $result := omit $map "F4" "F1" "F3" ]]
$result = map[F2:B F5:Z]

pick

func(dict map[string]interface{}, keys ...string) map[string]interface{}

The pick function selects just the given keys out of a dictionary, creating a new dict.

Examples


[[ $map    := dict "F1" "A" "F2" "B" ]]
[[ $result := pick $map "F2" ]]
$result = map[F2:B]

pluck

func(key string, d ...map[string]interface{}) []interface{}

The pluck function makes it possible to give one key and multiple maps, and get a list of all of the matches.

Application notes / Limits:

  • If the give key is not found in a map, that map will not have an item in the list (and the length of the returned list will be less than the number of dicts in the call to pluck.
  • If the key is found but the value is an empty value, that value will be inserted.
  • A common idiom in Sprig templates is to uses pluck… | first to get the first matching key out of a collection of dictionaries.

Examples


[[ $map    := dict "F1" "A" "F2" "B" ]]
[[ $result := pluck "F2" $map ]]
$result = [B]

complex example with dict and pluck command
[[ $map    := newMap  ]]
[[ $map    := dict "F1" "A" "F2" "B2" ]]
[[ $map1   := dict "F1" "A" "F2" "ValueB field F2 in $map1" ]]
[[ $result := pluck "F2" $map $map1]]
$result = [B2 ValueB field F2 in $map1]

example with not found
[[ $map    := newMap  ]]
[[ $map    := dict "F1" "A" "F2" "B2" ]]
[[ $map1   := dict "F1" "A" "F2" "ValueB field F2 in $map1" ]]
[[ $result := pluck "F9" $map $map1]]
$result = []

prepend

func(list interface{}, v interface{}) []interface{}

The prepend function adds an item onto the beginning of a list.

Examples


[[ $result := list "A" "B" "C" "D" ]]
[[ $result := prepend $list "BeforeA" ]]
$result = [BeforeA A B C D]

push

func(list interface{}, v interface{}) []interface{}

The push function adds an item onto the end of a list.

Application notes / Limits:

  • Alias-Name: append

Examples


[[ $result := list "A" "B" "C" "D" ]]
[[ $result := push $result "AfterD" ]]
$result = [A B C D AfterD]

rest

func(list interface{}) []interface{}

The rest function get the tail of the list (everything but the first item).

Application notes / Limits:

  • rest panics if there is a problem

Examples


[[ $result := rest ( list 1 2 3 4 )  ]]
$result = "[2 3 4]"

[[ $list := list "This" "is" "a" "test" "string" ]]
[[ $result := rest $list ]]
$result = [is a test string]

reverse

func(v interface{}) []interface{}

The reverse function produce a new list with the reversed elements of the given list.

Application notes / Limits:

  • reverse panics if there is a problem.

Examples


[[ $list := list "This" "is" "a" "test" "string" ]]
[[ $result := reverse $list ]]
$result = [string test a is This]

[[ $result := reverse ( list 1 2 3 4 )  ]]
$result = "[4 3 2 1]"

slice

func(list interface{}, indices ...interface{}) interface{}

The slice function cuts/slices a list.

It cuts the list based on 1 or 2 positional parameter (integer)

  • Enter only 1 parameter: the list is cut from left to right, based on the parameter positional value. All list items to the left will be kept.
  • Ebnter 2 positional parameter: the list is cut from the left based on first position, keeps the list items to the 2 position, and cuts the rest from the list.

Examples


[[ $result := slice ( list 1 2 3 4 5 ) 1 4 ]]
$result = [2 3 4]

[[ $list := list "This" "is" "a" "test" "string" ]]
[[ $result := slice $list 1 3 ]]
$result = [is a]

[[ $result := slice ( list 1 2 3 4 5 6 7 8 9 ) 7 ]]
$result = [8 9]

uniq

func(list interface{}) []interface{}

The uniq function contains only unique list entries.

Examples


[[ $result := uniq ( list 1 1 2 2 )]]
$result = [1 2]

[[ $result := uniq ( list 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 ) ]]
$result = [0 1 2 3 4 5 6 7 8 9]

[[ $result := uniq ( list "This" "is" "a" "test" "string" "This" "test" ) ]]
$result = [This is a test string]

values

func(dict map[string]interface{}) []interface{}

The values function contains an array with all the values of the map.

Examples


[[ $result := values ( mapSet ( dict "F1" "A" ) "F4" "D" ) ]]
$result = [A D]

[[ $map    := dict "firstName" "Max" ]]
[[ $map    := mapSet $map "lastName" "Muster" ]]
[[ $result := values $map ]]
$result = [Max Muster]

without

func(list interface{}, omit ...interface{}) []interface{}

The without function filters items out of a list.

Application notes / Limits:

  • without panics if there is a problem.

Examples


[[ $result := without ( list "This" "is" "a" "test" "string" ) "a" "string" ]]
$result = [This is test]

[[ $result := without ( list 1 2 3 4 ) 3 ]]
$result = [1 2 4]