Skip to content

Instantly share code, notes, and snippets.

@jrsinclair
Created December 5, 2018 22:12
Show Gist options
  • Save jrsinclair/40d2f6ea38fe62b6e0d5afcb407415f7 to your computer and use it in GitHub Desktop.
Save jrsinclair/40d2f6ea38fe62b6e0d5afcb407415f7 to your computer and use it in GitHub Desktop.
Elegant Error Handling Code Samples
function csvToMessages(csvData) {
const csvRows = splitCSVToRows(csvData);
const headerFields = csvRows.map(_.head).map(splitFields);
const dataRows = csvRows.map(_.tail);
const funcInEither = headerFields.map(processRows);
const messagesArr = dataRows.ap(funcInEither);
return either(showError, showMessages, messagesArr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment