All files / api/common/util map.ts

100% Statements 5/5
100% Branches 1/1
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13            2x 5x 2x   3x    
/**
 * data가 null이 아니라면 mapper(data)를 반환한다.
 * @param data nullable한 데이터
 * @param mapper NonNullable한 데이터를 인자로 받아 변형하는 함수
 * @returns null or mapper(data)
 */
export const map = <T, R>(data: T, mapper: (data: NonNullable<T>) => R) => {
  if (data == null) {
    return null;
  }
  return mapper(data);
};