Skip to content

Instantly share code, notes, and snippets.

@thinca
Forked from ujihisa/wordcount.vim
Last active March 11, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinca/29f7cc192a1d78d7095b728928b008cb to your computer and use it in GitHub Desktop.
Save thinca/29f7cc192a1d78d7095b728928b008cb to your computer and use it in GitHub Desktop.
let s:S = vital#vital#import('Data.String')
let s:L = vital#vital#import('Data.List')
function! s:count_words(text) abort
let F = { memo, x -> extend(memo, {x: get(memo, x, 0) + 1}) }
return s:L.foldl(F, {}, s:S.scan(a:text, '\w\+'))
endfunction
echo s:count_words('this is a pen or not a pen')
" {'this': 1, 'is': 1, 'a': 2, 'pen': 2, ...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment