-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathDict.txt
124 lines (105 loc) · 3.85 KB
/
Dict.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
*vital/Data/Dict.txt* dictionary utilities library.
Maintainer: thinca <[email protected]>
==============================================================================
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