Skip to content

Instantly share code, notes, and snippets.

@thinca

thinca/wordcount.vim

Forked from ujihisa/wordcount.vim
Last active Mar 11, 2019
Embed
What would you like to do?
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