diff --git a/README.md b/README.md index 06d69a2..e3300a9 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ new ConstructorWithMandatoryCallback(nop) a === identity(a) // => true ``` +**always** and **never** return true and false respectively + +```typescript +always() // => true +never() // => false +``` + **partial** applies a partial configuration object as first argument of compatible functions: ```typescript diff --git a/package.json b/package.json index f1792cb..9892afa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tk-functional", - "version": "0.1.2", + "version": "0.1.3", "description": "Typescript/Javascript helpers for functional-style programming", "source": "src/index.ts", "main": "dist/tk-functional.js", @@ -26,4 +26,4 @@ "tk-base": "^0.1.7" }, "dependencies": {} -} \ No newline at end of file +} diff --git a/src/index.test.ts b/src/index.test.ts index b0c8694..897a946 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,4 +1,4 @@ -import { partial, cmp, nop, identity } from "./index"; +import { always, cmp, identity, never, nop, partial } from "./index"; describe("nop", () => { it("does nothing", () => { @@ -35,3 +35,19 @@ describe("cmp", () => { expect(["c", "a", "b"].sort(cmp())).toEqual(["a", "b", "c"]); }); }); + +describe("always", () => { + it("returns true", () => { + expect(always()).toBe(true); + expect(always(true)).toBe(true); + expect(always(false)).toBe(true); + }); +}); + +describe("never", () => { + it("returns false", () => { + expect(never()).toBe(false); + expect(never(true)).toBe(false); + expect(never(false)).toBe(false); + }); +}); diff --git a/src/index.ts b/src/index.ts index 5e59064..9c7886b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,3 +37,13 @@ export function cmp(args?: Partial): (a: any, b: any) => number { } } } + +/** + * Predicate that always returns true + */ +export const always = (...args: any[]) => true + +/** + * Predicate that always returns false + */ +export const never = (...args: any[]) => false