Codementor Events

Extreme Reusability with Functional Programming & Lodash

Published Nov 07, 2019

There's many ways that people write code. While every coding style has its own strengths & weaknesses, all priotize that the code is reusable, testable, readable and functional (works).

import { flow, map, get, add, reduce } from 'lodash/fp'

const getScore = get('score')

export const countUserScores = flow(
  map(getScore),
  reduce(add)(0),
)

The code above is not only extremely reusable (composed functions) but also elegant. It takes an array of user objects with a score and counts them.

Over the course of my professional career I've come to appreciate the simple nature of functional programming and the inherent testability (no side effects).

Further reading:

Discover and read more posts from Matteo Demicheli
get started
post commentsBe the first to share your opinion
Show more replies