Skip to content

Commit

Permalink
feat: Add debug operator
Browse files Browse the repository at this point in the history
This operator can be inserted in a callbag chain (e.g. in a call to
`pipe`) to log all the events that flow through
  • Loading branch information
jvanbruegge committed May 2, 2021
1 parent 2c16f7a commit 89ba65d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ export function scan<A, B>(
});
};
}

export function debug<A>(msg: string | ((a: A) => void)): Operator<A, A> {
const f = typeof msg === 'function' ? msg : (x: A) => console.log(msg, x);
return map(x => {
f(x);
return x;
});
}

0 comments on commit 89ba65d

Please sign in to comment.