Vim documentation: vital/Data/Dict
main help file
vital/Data/Dict.txt dictionary utilities library.
Maintainer: thinca <thinca+vim@gmail.com>
==============================================================================
CONTENTS Vital.Data.Dict-contents
INTRODUCTION Vital.Data.Dict-introduction
INTERFACE Vital.Data.Dict-interface
FUNCTIONS Vital.Data.Dict-functions
==============================================================================
INTRODUCTION Vital.Data.Dict-introduction
Vital.Data.Dict is Dictionary Utilities Library.
It provides some functions to manipulate Dictionary.
==============================================================================
INTERFACE Vital.Data.Dict-interface
------------------------------------------------------------------------------
FUNCTIONS Vital.Data.Dict-functions
from_list({key-value-list}) Vital.Data.Dict.from_list()
Makes a dictionary from {key-value-list}.
{key-value-list} is one of following forms:
[key, value, key, value]
or
[[key, value], [key, value]]
make({keys}, {values} [, {fill}]) Vital.Data.Dict.make()
Makes a dictionary from {keys} and {values}.
If the length of {keys} is less than {values}, tails of {values} are
ignored.
If the length of {keys} is more than {values}, {values} are filled by
{fill}.
If {fill} is omitted, 0 is used.
:echo Dict.make(['one', 'two', 'three'], [1, 2, 3])
{'one': 1, 'two': 2, 'three': 3}
:echo Dict.make(['one', 'two', 'three'], [1, 2, 3, 4])
{'one': 1, 'two': 2, 'three': 3}
:echo Dict.make(['one', 'two', 'three'], [1, 2])
{'one': 1, 'two': 2, 'three': 0}
:echo Dict.make(['one', 'two', 'three'], [1, 2], 9)
{'one': 1, 'two': 2, 'three': 9}
swap({dict}) Vital.Data.Dict.swap()
Makes a dictionary that swapped keys and values.
:echo Dict.swap({'one': 1, 'two': 2, 'three': 3})
{'1': 'one', '2': 'two', '3': 'three'}
make_index({list} [, {value}]) Vital.Data.Dict.make_index()
Makes an index dictionary. This dictionary has {list} as key, and has
{value} as each value.
If {value} is omitted, 1 is used.
:echo Dict.make_index(['apple', 'orange', 'banana'])
{'apple': 1, 'orange': 1, 'banana': 1}
:echo Dict.make_index(['apple', 'orange', 'banana'], 5)
{'apple': 5, 'orange': 5, 'banana': 5}
pick({dict}, {keys}) Vital.Data.Dict.pick()
Returns a copy of the {dict}, filtered to only have entries for the
whitelisted {keys}.
:let d = {'one' : 1, 'two' : 2, 'three' : 3}
:echo Dict.pick(d, ['one', 'three'])
{'one': 1, 'three': 3}
omit({dict}, {keys}) Vital.Data.Dict.omit()
Returns a copy of the {dict}, filtered to omit the blacklisted {keys}.
:let d = {'one' : 1, 'two' : 2, 'three' : 3}
:echo Dict.omit(d, ['one', 'three'])
{'two': 2}
clear({dict}) Vital.Data.Dict.clear()
Remove all the elements of {dict}. Returns the empty dictionary
{dict}.
:let d = {'one' : 1, 'two' : 2, 'three' : 3}
:echo Dict.clear(d)
{}
:echo d
{}
max_by({dict}, {expr}) Vital.Data.Dict.max_by()
Returns a list [key, val] which is maximum value in {dict} through
given {expr}.
Throws an exception if {dict} is empty.
both "v:key" and "v:val" can be used in {expr}.
:echo Dict.max_by({'alice' : 1, 'bob' : 2, 'carol' : 3}, 'len(v:key) - v:val')
['alice', 1]
min_by({dict}, {expr}) Vital.Data.Dict.min_by()
Returns a list [key, val] which is minimum value in {dict} through
given {expr}.
Throws an exception if {dict} is empty.
both "v:key" and "v:val" can be used in {expr}.
:echo Dict.min_by({'alice' : 1, 'bob' : 2, 'carol' : 3}, 'len(v:key) - v:val')
['bob', 2]
foldl({f}, {init}, {dict}) Vital.Data.Dict.foldl()
TODO
Behaves like Haskell's Data.Map.Lazy.foldlWithKey().
foldr({f}, {init}, {dict}) Vital.Data.Dict.foldr()
TODO
Behaves like Haskell's Data.Map.Lazy.foldrWithKey().
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl
top - main help file - tag index