Skip to content

Instantly share code, notes, and snippets.

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

  • Save Parables/5e239e568295b29a53352f473622c17c to your computer and use it in GitHub Desktop.

Select an option

Save Parables/5e239e568295b29a53352f473622c17c 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