Skip to content

Instantly share code, notes, and snippets.

@tyru
Last active Aug 6, 2019
Embed
What would you like to do?
function! HasKey(dict, key)
return has_key(a:dict, a:key)
endfunction
function! s:has_key(dict, key)
return has_key(a:dict, a:key)
endfunction
function! Fold(list, init, f)
let l:V = a:init
for l:Elem in a:list
let l:V = a:f(l:V, l:Elem)
endfor
return l:V
endfunction
function! s:fold(list, init, f)
return Fold(a:list, a:init, a:f)
endfunction
function! s:main()
echo {'foo': 42}->HasKey('foo')
echo range(1,10)->Fold(0, {acc,n -> acc + n})
echo {'foo': 42}->s:has_key('foo')
echo range(1,10)->s:fold(0, {acc,n -> acc + n})
let l:Percent = {x -> x * 100}
echo (10.0 / 100.0)->l:Percent()
echo 2->{n -> n * 2}
echo 'hello'->{s -> execute('echon s')}
echo HasKey({'foo': 42}, 'foo')
echo Fold(range(1,10), 0, {acc,n -> acc + n})
endfunction
call s:main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment