git ssb

0+

Dominic / %DqZuyvY14e7IX0U6cAj…



Tree: 6b099fb2cf92d238df76e99ebab6e3a13c9149d0

Files: 6b099fb2cf92d238df76e99ebab6e3a13c9149d0 / evolve.js

548 bytesRaw
1function append(ary, ary2) {
2 if(!Array.isArray(ary2))
3 ary.push(ary2)
4 else
5 while(ary2.length)
6 ary.push(ary2.shift())
7 return ary
8}
9
10module.exports = function evolve (update, act, state, events) {
11 do {
12 var next = update(state, events.shift())
13 state = next.state
14 if(Array.isArray(next.effects)) {
15 while(next.effects.length)
16 append(events, act(state, next.effects.shift())||[])
17 } else if(next.effects)
18 append(events, act(state, next.effects) || [])
19 }
20 while(events.length)
21
22 return state
23}
24
25

Built with git-ssb-web