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
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
//OVERWRITING Underscore.js's templates | |
// By default, Underscore uses ERB-style template delimiters, change the | |
// following template settings to use alternative delimiters. | |
_.templateSettings = { | |
evaluate : /<%([\s\S]+?)%>/g, | |
interpolate : /<%=([\s\S]+?)%>/g, | |
escape : /<%-([\s\S]+?)%>/g | |
value : /<%@([\s\S]+?)%>/g // inserts value of a variable on the object or "" if undefined | |
}); |
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
// [BCKW](https://en.wikipedia.org/wiki/B,C,K,W_system) | |
// compose | |
var B = f => g => a => f(g(a)) | |
// flip | |
var C = f => a => b => f(b)(a) | |
// Const | |
var K = a => b => a |
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
// 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); |
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
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 |
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
Lenses | |
====== | |
What is a lens? | |
--------------- | |
pair of getter and setter that perform immutable updates on parameterized data structure | |
e.g. | |
```js |
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
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 |
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
// 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
- Doesn't do a lot for you. Just makes it easy to do async actions
NewerOlder