Skip to content

Instantly share code, notes, and snippets.

@abdulhannanali
Last active November 29, 2016 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdulhannanali/a1d7e62344cec24adb4a770200411122 to your computer and use it in GitHub Desktop.
Save abdulhannanali/a1d7e62344cec24adb4a770200411122 to your computer and use it in GitHub Desktop.
Question: Is the function that returns a promise can be considered pure? The returned function might be performing I/O
import axios from 'axios'
/**
* getIdentity
* returns a Promise provided the name of the user
*/
function getIdentity (name) {
return axios.get('https://getyourinfo.pk/' + name)
}
@ericelliott
Copy link

ericelliott commented Nov 29, 2016

No. Pure functions have two rules:

  1. Given the same input, always return the same output.
  2. No side-effects. Network I/O is a side-effect. Any kind of I/O is a side-effect.

See "Master the JavaScript Interview: What is a pure function?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment