itsabdelrahman / functional-conditional

🐏 Conditional Logic: The Functional Way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

functional-conditional

Conditional Logic: The Functional Way

Usage

Turn this:

let result = null;

switch (someValue) {
  case 0:
    result = 'zero';
    break;
  case 1:
    result = 'one';
    break;
  case 2:
    result = 'two';
    break;
}

Into this:

import conditional from 'functional-conditional';

const result = conditional<number, string>([
  { if: 0, then: 'zero' },
  { if: 1, then: 'one' },
  { if: 2, then: 'two' },
])(someValue);

License

MIT

About

🐏 Conditional Logic: The Functional Way


Languages

Language:TypeScript 100.0%