Robert Penner
1 min readAug 1, 2016

--

Excellent functional refactoring, Victor.

One bit of non-generic code remains:

type Predicate = (e: Employee) => boolean;

This infects and(), making it non-generic.

Easy to fix:

type Predicate<T> = (value: T) => boolean;

function and<T>(predicates: Predicate<T>[]): Predicate<T> { …

function filteredSalaries(employees: Employee[], conditions: Predicate<Employee>[]): number[] { …

I collected the code in a single gist with my tweaks:

--

--

Robert Penner

JavaScript dev at @workandco | easing functions author | formerly Adobe, Disney, VICE | Nepal articles are at https://medium.com/@robpenner_nepal