API
Dict
Squiggle dictionaries work similar to Python dictionaries. The syntax is similar to objects in Javascript.
Conversions
toList
Dict.toList(Dict('A)) => List([String, 'A])
Dict.toList({a: 1, b: 2})fromList
Dict.fromList(List([String, 'A])) => Dict('A)
Dict.fromList([
["foo", 3],
["bar", 20],
]) // {foo: 3, bar: 20}Transformations
set
Creates a new dictionary that includes the added element, while leaving the original dictionary unaltered.
Dict.set(Dict('A), String, 'A) => Dict('A)
Dict.set({a: 1, b: 2}, "c", 3)delete
Creates a new dictionary that excludes the deleted element.
Dict.delete(Dict('A), String) => Dict('A)
Dict.delete({a: 1, b: 2}, "a")merge
Dict.merge(Dict(any), Dict(any)) => Dict(any)
first = { a: 1, b: 2 }
snd = { b: 3, c: 5 }
Dict.merge(first, snd)mergeMany
Dict.mergeMany(List(Dict(any))) => Dict(any)
first = { a: 1, b: 2 }
snd = { b: 3, c: 5 }
Dict.mergeMany([first, snd]) // {a: 1, b: 3, c: 5}map
Dict.map(Dict('A), ('A) => 'B) => Dict('B)
Dict.map({a: 1, b: 2}, {|x| x + 1})mapKeys
Dict.mapKeys(Dict('A), (String) => String) => Dict('A)
omit
Creates a new dictionary that excludes the omitted keys.
Dict.omit(Dict('A), List(String)) => Dict('A)
data = { a: 1, b: 2, c: 3, d: 4 }
Dict.omit(data, ["b", "d"]) // {a: 1, c: 3}Queries
has
Dict.has(Dict(any), String) => Bool
Dict.has({a: 1, b: 2}, "c")size
Dict.size(Dict(any)) => Number
Dict.size({a: 1, b: 2})keys
Dict.keys(Dict(any)) => List(String)
Dict.keys({a: 1, b: 2})values
Dict.values(Dict('A)) => List('A)
Dict.values({ foo: 3, bar: 20 }) // [3, 20]pick
Creates a new dictionary that only includes the picked keys.
Dict.pick(Dict('A), List(String)) => Dict('A)
data = { a: 1, b: 2, c: 3, d: 4 }
Dict.pick(data, ["a", "c"]) // {a: 1, c: 3}