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
const countSubstringMatches = (str: string, substr: string, startAt: number) => { | |
const substringLength = substr.length; | |
let count = 1; | |
for ( | |
let substringPos = str.indexOf(substr, startAt + substringLength); | |
substringPos >= 0; | |
++count | |
) | |
substringPos = str.indexOf(substr, substringPos + substringLength); | |
return count; |
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
const dangerousPushAll = (xs, ys) => { | |
for (const y in ys) { | |
xs.push(y); | |
} | |
return xs; | |
} |
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
// @flow strict-local | |
// Lenses | |
// ------------------------------------------------------------------------------------------------ | |
export type LensInternal<S, T, A, B> = { | |
getVal: (S) => A, | |
setVal: (B, S) => T, | |
}; |
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
import fs from 'fs'; | |
const data = fs.readFileSync('/path/to/my/copy/of/input.txt'); | |
const input = data.toString('utf-8').split('\n').filter(x => x !== '').map(x => parseInt(x)); | |
// Chop goes through the array, but gives you less and less of it each time. If you fed it [1, 2, 3], then | |
// the first iteration would get [1, 2, 3], the next would get [2, 3] and the final would get [3]. Idea is stolen | |
// from fp-ts: https://gcanti.github.io/fp-ts/modules/ReadonlyArray.ts.html#chop | |
const chop = (f) => (arr) => [...(new Array(arr.length))].map((_, i) => f(arr.slice(i))); |
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
const setAttr = _.curry((attrName, el, val) => { el.setAttribute(val)); return el; }); | |
const listen = _.curry((evtName, el, f) => { el.addEventListener(evtName, f); return el; }) | |
const bindCreateResultButton = (createResultButton, postTextarea, getPostData, preTextarea) => | |
_.compose( | |
listen('click', createResultButton), | |
_.compose(x => () => setAttr('value', postTextArea, x), getPostData), | |
)(preTextArea); |
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); | |
const processRowsA = liftA2(processRows); | |
const messagesArr = processRowsA(headerFields, dataRows); | |
return either(showError, showMessages, messagesArr); | |
} |
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 liftA2(func) { | |
return function runApplicativeFunc(a, b) { | |
return b.ap(a.map(func)); | |
}; | |
} |
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); | |
const funcInEither = headerFields.map(processRows); | |
const messagesArr = dataRows.ap(funcInEither); | |
return either(showError, showMessages, messagesArr); | |
} |
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
/* Rest of Left class is hidden to save space */ | |
// Ap In Left (the sad path) | |
ap() { | |
return this; | |
} |
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); | |
// How will we pass headerFields and dataRows to | |
// processRows() ? | |
const funcInEither = headerFields.map(processRows); | |
} |
NewerOlder