Skip to content

Commit

Permalink
refactor(transducers-fsm): use arrow fns
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 5, 2019
1 parent 48670f5 commit e103d74
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions packages/transducers-fsm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,26 @@ export interface FSMOpts<T extends FSMState, A, B> {
*
* @param opts
*/
export function fsm<T extends FSMState, A, B>(opts: FSMOpts<T, A, B[]>): Transducer<A, B> {
return comp((rfn: Reducer<any, B>) => {
const states = opts.states;
const state = opts.init();
const r = rfn[2];
return compR(rfn,
(acc, x) => {
const res = states[<any>state.state](state, x);
if (res != null) {
for (let i = 0, n = (<B[]>res).length; i < n; i++) {
acc = r(acc, res[i]);
if (isReduced(acc)) {
break;
export const fsm =
<T extends FSMState, A, B>(opts: FSMOpts<T, A, B[]>): Transducer<A, B> =>
comp((rfn: Reducer<any, B>) => {
const states = opts.states;
const state = opts.init();
const r = rfn[2];
return compR(rfn,
(acc, x) => {
const res = states[<any>state.state](state, x);
if (res != null) {
for (let i = 0, n = (<B[]>res).length; i < n; i++) {
acc = r(acc, res[i]);
if (isReduced(acc)) {
break;
}
}
}
}
if (state.state === opts.terminate) {
return ensureReduced(acc);
}
return acc;
});
});
}
if (state.state === opts.terminate) {
return ensureReduced(acc);
}
return acc;
});
});

0 comments on commit e103d74

Please sign in to comment.