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 compare | |
* @description function compares two arrays with ids to figure out: are they equal? (elements position can be different) | |
* @param arraFrom {Array} | |
* @param arraTo {Array} | |
* @param compareFunction {Function} | |
* @returns {Boolean} | |
*/ | |
function compare(arrayFrom, arrayTo, compareFunction) { |
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
compare : List a -> List a -> Maybe (a -> a -> Bool) -> Bool | |
compare list1 list2 callback = | |
if (List.length list1) /= (List.length list2) then | |
False | |
else | |
let | |
test a b = | |
case callback of | |
Just cb -> | |
cb a b |
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 Either from 'data.either' | |
import Task from 'data.task' | |
// We don't want to tie ourselves to any global environment so Task here | |
const win = new Task((rej, res) => res(window)) | |
const nav = new Task((rej, res) => res(navigator)) | |
// We chain because we want to work with `win` (another Task) if nothing's found. | |
const userAgent = nav | |
.chain(n => |
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 service = { | |
getUsers: () => fetch(`https://jsonplaceholder.typicode.com/users`), | |
getGroups: () => fetch(`https://jsonplaceholder.typicode.com/posts`) | |
}; | |
async function getData() { | |
try { | |
const peoplePromise = await service.getUsers(); | |
const groupsPromise = await service.getGroups(); | |
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
.truncate { | |
width: 250px; | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} |
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
// Functor => F.map | |
/* | |
laws | |
const id = x => x | |
*/ | |
//fx.map(f).map(g) === fx.map(x => g(f(x))) | |
//fx.map(id) === id(fx) | |
// Monad => F.of, chain (also: flatMap, bind, >>=) |
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 Task = require('data.task'); | |
const fetch = require('node-fetch'); | |
// futurizeP :: (* -> Promise a b) -> * -> Task a b | |
const futurizeP = require('futurize').futurizeP(Task); | |
// fetchJson_ :: Url -> Promise Error Object | |
const fetchJson_ = url => fetch(url).then(res => res.json()); | |
// fetchJson :: Url -> Task Error Object |
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
let clicks$ = Rx.Observable.fromEvent(document.getElementById('button'), 'click'); | |
clicks$ | |
.buffer(clicks$.debounce(250)) | |
.map(list => list.length) | |
.filter(x => x === 2) | |
.subscribe(() => { | |
console.log('doubleclick'); | |
}) |
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
// TS | |
const randomColorGenerator = (): string => | |
`#${(Math.random().toString(16) + '0000000').slice(2, 8)}`; | |
// ES6 | |
const randomColorGenerator = () => | |
`#${(Math.random().toString(16) + '0000000').slice(2, 8)}`; | |
// ES5 | |
var randomColorGenerator = function () { |