Skip to content

Instantly share code, notes, and snippets.

@tyru
Last active August 6, 2019 20:39
Show Gist options
  • Save tyru/19cc4e67460f365e902282ec528da6ea to your computer and use it in GitHub Desktop.
Save tyru/19cc4e67460f365e902282ec528da6ea to your computer and use it in GitHub Desktop.
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