Skip to content

Instantly share code, notes, and snippets.

@stoeffel
Created May 18, 2016 11:59
Show Gist options
  • Save stoeffel/5561124c380a8313548f809111c5905a to your computer and use it in GitHub Desktop.
Save stoeffel/5561124c380a8313548f809111c5905a to your computer and use it in GitHub Desktop.
const l = console::console.log
const safeProp = prop => R.compose(S.toMaybe, R.prop(prop))
const withDefault = R.curry((def, safeFun) => (...args) => {
const maybe = safeFun(...args)
return S.maybe(def, R.identity, maybe)
})
const name = withDefault('anon', safeProp('name'))
l(name({name: 'foo'}))
l(name({nope: 'foo'}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment