git ssb

16+

Dominic / patchbay



Tree: ae7c2d638a47d2b374cec6c88e45d20c4290fe33

Files: ae7c2d638a47d2b374cec6c88e45d20c4290fe33 / util.js

853 bytesRaw
1var pull = require('pull-stream')
2var Next = require('pull-next')
3
4function first (list, test) {
5 for(var i in list) {
6 var value = test(list[i], i, list)
7 if(value) return value
8 }
9}
10
11function decorate (list, value, caller) {
12 caller = caller || function (d,e,v) { return d(e, v) }
13
14 return list.reduce(function (element, decorator) {
15 return caller(decorator, element, value) || element
16 }, null)
17}
18
19exports.first = first
20
21exports.decorate = decorate
22
23exports.next = function (createStream, opts, range, property) {
24
25 range = range || opts.reverse ? 'lt' : 'gt'
26 property = property || 'timestamp'
27
28 var last = null
29 return Next(function () {
30 if(last) {
31 opts[range] = last[property]
32 }
33 return pull(
34 createStream(opts),
35 pull.through(function (msg) {
36 if(!msg.sync) last = msg
37 })
38 )
39 })
40}
41

Built with git-ssb-web