79470853

Date: 2025-02-26 19:36:17
Score: 1
Natty:
Report link

I modified @Barremian's response to type the predicate and pass on the value on tap so it functions more closely to an actual tap function:

export const isFirst = <T>(predicate: (t: T) => void) => {
  let first = true;
  return (source: Observable<T>) => {
    return source.pipe(
      tap({
        next: (value: T) => {
          if (first) {
            predicate(value);
            first = false;
          }
        },
      }),
    );
  };
};
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @Barremian's
  • Low reputation (0.5):
Posted by: Galen Howlett