dict.vim 632 B

1234567891011121314151617181920212223242526272829303132
  1. scriptencoding utf-8
  2. function! coc#dict#equal(one, two) abort
  3. for key in keys(a:one)
  4. if a:one[key] != a:two[key]
  5. return 0
  6. endif
  7. endfor
  8. return 1
  9. endfunction
  10. " Return new dict with keys removed
  11. function! coc#dict#omit(dict, keys) abort
  12. let res = {}
  13. for key in keys(a:dict)
  14. if index(a:keys, key) == -1
  15. let res[key] = a:dict[key]
  16. endif
  17. endfor
  18. return res
  19. endfunction
  20. " Return new dict with keys only
  21. function! coc#dict#pick(dict, keys) abort
  22. let res = {}
  23. for key in keys(a:dict)
  24. if index(a:keys, key) != -1
  25. let res[key] = a:dict[key]
  26. endif
  27. endfor
  28. return res
  29. endfunction