Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function! HasKey(dict, key)
  2. return has_key(a:dict, a:key)
  3. endfunction
  4. function! s:has_key(dict, key)
  5. return has_key(a:dict, a:key)
  6. endfunction
  7.  
  8. function! Fold(list, init, f)
  9. let l:V = a:init
  10. for l:Elem in a:list
  11. let l:V = a:f(l:V, l:Elem)
  12. endfor
  13. return l:V
  14. endfunction
  15. function! s:fold(list, init, f)
  16. return Fold(a:list, a:init, a:f)
  17. endfunction
  18.  
  19. function! s:main()
  20. echo {'foo': 42}->HasKey('foo')
  21. echo range(1,10)->Fold(0, {acc,n -> acc + n})
  22.  
  23. echo {'foo': 42}->s:has_key('foo')
  24. echo range(1,10)->s:fold(0, {acc,n -> acc + n})
  25.  
  26. let l:Percent = {x -> x * 100}
  27. echo (10.0 / 100.0)->l:Percent()
  28.  
  29. echo 2->{n -> n * 2}
  30. echo 'hello'->{s -> execute('echon s')}
  31.  
  32. echo HasKey({'foo': 42}, 'foo')
  33. echo Fold(range(1,10), 0, {acc,n -> acc + n})
  34. endfunction
  35.  
  36. call s:main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement