Skip to content

Instantly share code, notes, and snippets.

@Parables
Created June 5, 2021 09:14
Show Gist options
  • Select an option

  • Save Parables/93e78f596429e7674d0e76cec070c758 to your computer and use it in GitHub Desktop.

Select an option

Save Parables/93e78f596429e7674d0e76cec070c758 to your computer and use it in GitHub Desktop.
Monads using null. Clever tricky by Nathan Franck http://disq.us/p/266tez0
function getSupervisorName(enteredId: string | null) {
let employee, supervisor;
if (null != enteredId &&
null != (employee = repository.findById(parseInt(enteredId))) &&
null != employee.supervisorId &&
null != (supervisor = repository.findById(employee.supervisorId)))
return supervisor.name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment