This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processRows(headerFields) { | |
return function processRowsWithHeaderFields(dataRows) { | |
// Note this is Array map, not Either map. | |
return dataRows.map(row => processRow(headerFields, row)); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function csvToMessages(csvData) { | |
const csvRows = splitCSVToRows(csvData); | |
const headerFields = csvRows.map(_.head).map(splitFields); | |
const dataRows = csvRows.map(_.tail); | |
// What’s next? | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitCSVToRows(csvData) { | |
// There should always be a header row... so if there's no | |
// newline character, something is wrong. | |
return (csvData.indexOf('\n') < 0) | |
? left('No header row found in CSV data') | |
: right(csvData.split('\n')); | |
} | |
function processRows(headerFields, dataRows) { | |
// Note this is Array map, not Either map. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processRow(headerFields, row) { | |
const rowObjWithDate = right(row) | |
.map(splitFields) | |
.chain(zipRow(headerFields)) | |
.chain(addDateStr); | |
return either(showError, rowToMessage, rowObjWithDate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processRow(headerFields, row) { | |
const fieldsEither = right(row).map(splitFields); | |
const rowObj = fieldsEither.chain(zipRow(headerFields)); | |
const rowObjWithDate = rowObj.chain(addDateStr); | |
return either(showError, rowToMessage, rowObjWithDate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processRow(headerFields, row) { | |
const fieldsEither = right(row).map(splitFields); | |
const rowObj = fieldsEither.chain(zipRow(headerFields)); | |
const rowObjWithDate = rowObj.chain(addDateStr); | |
// Slowly getting better... but what do we return? | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function either(leftFunc, rightFunc, e) { | |
return (e instanceof Left) ? leftFunc(e._value) : rightFunc(e._value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*Left represents the sad path. | |
*/ | |
class Left { | |
constructor(val) { | |
this._value = val; | |
} | |
map() { | |
// Left is the sad path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function processRow(headerFields, row) { | |
const fieldsEither = right(row).map(splitFields); | |
const rowObj = fieldsEither.map(zipRow(headerFields)).join(); | |
const rowObjWithDate = rowObj.map(addDateStr).join(); | |
// Slowly getting better... but what do we return? | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*Left represents the sad path. | |
*/ | |
class Left { | |
constructor(val) { | |
this._value = val; | |
} | |
map() { | |
// Left is the sad path |