From 48f0b07a79f70eacec4ed22f290a8d15b3d95a19 Mon Sep 17 00:00:00 2001 From: drizzer14 Date: Wed, 23 Nov 2022 17:37:58 +0200 Subject: [PATCH] feat!: remove `ternary` function --- src/ternary.ts | 20 ----------------- tests/ternary.spec.ts | 52 ------------------------------------------- 2 files changed, 72 deletions(-) delete mode 100644 src/ternary.ts delete mode 100644 tests/ternary.spec.ts diff --git a/src/ternary.ts b/src/ternary.ts deleted file mode 100644 index c0b2b22..0000000 --- a/src/ternary.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @module Ternary - */ - -import type { Map } from './types/map' - -/** - * Functional alternative to the ternary operator. - * Enforces the same return type for both branches, - * the result is evaluated lazily. - */ -export default function ternary ( - predicate: Map, - left: Map, - right: Map, -): Map { - return (value) => { - return predicate(value) ? left(value) : right(value) - } -} diff --git a/tests/ternary.spec.ts b/tests/ternary.spec.ts deleted file mode 100644 index e4d588b..0000000 --- a/tests/ternary.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import sut from '../src/ternary' -import type { Map } from '../src/types/map' - -describe('ternary', () => { - describe('when predicate returns "true"', () => { - let left: Map - let right: jest.Mock - let result: number - - beforeEach(() => { - left = (value) => value + 1 - right = jest.fn() - result = sut( - () => true, - left, - right - )(1) - }) - - it('should return value from "left"', () => { - expect(result).toBe(2) - }) - - it('should not call "right"', () => { - expect(right).not.toHaveBeenCalled() - }) - }) - - describe('when predicate returns "false"', () => { - let left: jest.Mock - let right: Map - let result: number - - beforeEach(() => { - left = jest.fn() - right = (value) => value + 1 - result = sut( - () => false, - left, - right - )(1) - }) - - it('should return value from "right"', () => { - expect(result).toBe(2) - }) - - it('should not call "left"', () => { - expect(left).not.toHaveBeenCalled() - }) - }) -})