Explicit Function Arity

Published: 6/1/2020
Last edited: 2/1/2022

const inputs = '54321'.split('')
const results = inputs.map(parseInt)
view raw imperative.js hosted with ❤ by GitHub

import {map} from 'ramda'
const inputs = '54321'.split('')
const results = map(parseInt, inputs)
// const parseInts = map(parseInt)
// const results = parseInts(inputs)
view raw functional.js hosted with ❤ by GitHub

As you can see, parseInt doesn't behave as we expect.

For your own edification:

  1. Why does the imperative example behave this way?
  2. Why does the functional example work as expected?
  3. If we wanted to have the functional example work exactly as the imperative example, what would that look like?
Published: 6/1/2020
Last edited: 2/1/2022
Content by brekk
See this page on Github
Built with 💛 by Open Sorcerers
Created with Gatsby using the 😎 foresight starter