Skip to content

Commit 8cff8be

Browse files
update callbag.vim to 62a31fd03dfceb0e94a19295a1f6d3d0f2a954ed to support reduce() (#1009)
1 parent d2cbe80 commit 8cff8be

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

autoload/lsp/callbag.vim

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" https://github.com/prabirshrestha/callbag.vim#c721874292709dcf9024496e85f06236f56f66bf
1+
" https://github.com/prabirshrestha/callbag.vim#62a31fd03dfceb0e94a19295a1f6d3d0f2a954ed
22
" :CallbagEmbed path=autoload/lsp/callbag.vim namespace=lsp#callbag
33

44
let s:undefined_token = '__callbag_undefined__'
@@ -1246,6 +1246,36 @@ function! s:scanSourceCallback(data, t, d) abort
12461246
endfunction
12471247
" }}}
12481248

1249+
" reduce() {{{
1250+
function! lsp#callbag#reduce(reducer, seed) abort
1251+
let l:data = { 'reducer': a:reducer, 'seed': a:seed }
1252+
return function('s:reduceSource', [l:data])
1253+
endfunction
1254+
1255+
function! s:reduceSource(data, source) abort
1256+
let a:data['source'] = a:source
1257+
return function('s:reduceFactory', [a:data])
1258+
endfunction
1259+
1260+
function! s:reduceFactory(data, start, sink) abort
1261+
if a:start != 0 | return | endif
1262+
let a:data['sink'] = a:sink
1263+
let a:data['acc'] = a:data['seed']
1264+
call a:data['source'](0, function('s:reduceSourceCallback', [a:data]))
1265+
endfunction
1266+
1267+
function! s:reduceSourceCallback(data, t, d) abort
1268+
if a:t == 1
1269+
let a:data['acc'] = a:data['reducer'](a:data['acc'], a:d)
1270+
elseif a:t == 2 && lsp#callbag#isUndefined(a:d)
1271+
call a:data['sink'](1, a:data['acc'])
1272+
call a:data['sink'](2, lsp#callbag#undefined())
1273+
else
1274+
call a:data['sink'](a:t, a:d)
1275+
endif
1276+
endfunction
1277+
" }}}
1278+
12491279
" switchMap() {{{
12501280
function! lsp#callbag#switchMap(makeSource, ...) abort
12511281
let l:data = { 'makeSource': a:makeSource }

0 commit comments

Comments
 (0)