Skip to content

always() function

주어진 값을 항상 반환하는 함수를 반환합니다.

Signature:

typescript
declare function always<T>(value: T): (...args: any[]) => T;

Example

ts
const alwaysFive = always(5);
alwaysFive(); // 5

const defaultToEmpty = always("");
await Promise.reject("error during operation").catch(defaultToEmpty); // ""

// with pipe
const excludeNegatives = false;
pipe(
  [-1, 1, 2, 0, -3],
  filter(excludeNegatives ? lt(0) : always(true)),
  toArray,
); // [-1, 1, 2, 0 ,-3]

Open Source Code

Released under the Apache-2.0 License.