A form of documentation that helps developers understand what a function does.
// toUpper :: String -> String
const toUpper = str => str.toUpperCase()https://github.com/paldepind/flyd
License: MIT
Size: 22.4 KB (3.4 KB gzip)
Functions: 16
Project Life: Good
Stars: 1129
Code Quality: Good Functional/Procedural
Comments: JSDoc
Quality Automation: Extensive unit tests, CI
| // Immutable update techniques | |
| // mutate in place | |
| myData.x.y.z = 7; | |
| myData.a.b.push(9); | |
| mydata.a.b[2] = 3; | |
| // clone and mutate | |
| const newData = deepCopy(myData); | |
| newData.x.y.z = 7; |
Note: These aren't necessarily mutually exclusive. E.g. we may want to use promise with thunk to get better ergonomics for certain kinds of effects.
Learnability: 4
Testability: 4
Happy path: 4
Purity: 2
SLOC: 14
| O(1) - Trivial, we've done something almost exactly like this and it wont take long to complete at all | |
| O(log n) - Need to add a small capability then it's copy-pasta | |
| O(n) - Simple, It's like things we've done before. No refactoring or architectural changes needed. | |
| O(n^2) - Going to need to rework some things and watch out for regressions | |
| O(n!) - Major rework needed, lots of risk | |
| O(MG) - This is so complex or ill-defined that it may never complete |
| Lenses | |
| ====== | |
| What is a lens? | |
| --------------- | |
| pair of getter and setter that perform immutable updates on parameterized data structure | |
| e.g. | |
| ```js |
| moment(0) // epoc | |
| moment(undefined) // Now | |
| moment(null) // Invalid Date | |
| moment(false) // throw warning, Invalid date | |
| moment(void 0) // Now | |
| moment('') // Invlid Date | |
| moment([]) // Now | |
| moment({}) // Now |
| // Take string and get words as an array. Valid split characters are `,` `.` `\s` `/` `\n` | |
| // words :: String -> [String] | |
| export const words = str => | |
| (str ? str.split(/[\s\n.,/]+/) : []) // split on whitespace | |
| .filter(Boolean); |