|
1 |
| -" https://github.com/prabirshrestha/callbag.vim#c721874292709dcf9024496e85f06236f56f66bf |
| 1 | +" https://github.com/prabirshrestha/callbag.vim#62a31fd03dfceb0e94a19295a1f6d3d0f2a954ed |
2 | 2 | " :CallbagEmbed path=autoload/lsp/callbag.vim namespace=lsp#callbag
|
3 | 3 |
|
4 | 4 | let s:undefined_token = '__callbag_undefined__'
|
@@ -1246,6 +1246,36 @@ function! s:scanSourceCallback(data, t, d) abort
|
1246 | 1246 | endfunction
|
1247 | 1247 | " }}}
|
1248 | 1248 |
|
| 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 | + |
1249 | 1279 | " switchMap() {{{
|
1250 | 1280 | function! lsp#callbag#switchMap(makeSource, ...) abort
|
1251 | 1281 | let l:data = { 'makeSource': a:makeSource }
|
|
0 commit comments