This file contains hidden or 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
| // SUBJECT | |
| // Write a function withParamTransform which, | |
| // for any function f, | |
| // for any parameter transformation such as (a, b, c) => (a, c, b) (inverting 2 parameters) | |
| // satisfies the following condition: | |
| withParamTransform(f)[(a, b, c) => (a, c, b)](1, 2, 3) === f(1, 3, 2) | |
| // A more realistic example | |
| const minus = (a, b) => a - b | |
| minus(5, 2) === 3 // true |
This file contains hidden or 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 { renderNothing, lifecycle } from 'recompose'; | |
| /** | |
| * HOC to navigate to a dynamically computed route name | |
| * React Navigation does currently not accept a function to determine | |
| * the initial route at runtime | |
| */ | |
| const withDynamicInitialRouteName = Navigator => (screens, config = {}) => { | |
| if (typeof config.initialRouteName === 'function') { | |
| const getInitialRouteName = config.initialRouteName; |
This file contains hidden or 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 { compose, get, mergeWith, reduce } from 'conductor' | |
| const character_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
| const fetchJSON = url => fetch(url).then(res => res.json()) | |
| const fetchCharacter = id => fetchJSON(`https://swapi.co/api/people/${id}`) | |
| const getHomeworldName = compose(get('name'), fetchJSON, get('homeworld'), fetchCharacter) | |
| const toObj = (key, value) => ({ [key]: value }) | |
| const countOne = name => toObj(name, 1) | |
| const countHomeworld = compose(countOne, getHomeworldName) | |
| const mergeByAdding = mergeWith(add) |
This file contains hidden or 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 { filter } from 'conductor' | |
| const obj = { books: 10, ruler: 1, pencils: 5 } | |
| const isEven = x => Promise.resolve(x % 2 === 0) | |
| const result = await filter(isEven, obj) // { books: 10 } |
This file contains hidden or 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 obj = { books: 10, ruler: 1, pencils: 5 } | |
| const isEven = x => Promise.resolve(x % 2 === 0) | |
| const result = await Promise | |
| .all(Object.values(obj).map(isEven)) | |
| .then(results => Object.keys(obj).reduce((acc, key, index) => { | |
| if (results[index]){ | |
| acc[key] = obj[key] | |
| } | |
| return acc | |
| }, {}) // { books: 10 } |
This file contains hidden or 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 { filter } from 'conductor' | |
| const numbers = [3, 1, 4] | |
| const isEven = x => Promise.resolve(x % 2 === 0) | |
| const result = await filter(isEven, numbers) // [4] |
This file contains hidden or 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 numbers = [3, 1, 4] | |
| const isEven = x => Promise.resolve(x => x % 2 === 0) | |
| const result = await Promise | |
| .all(numbers.map(isEven))) | |
| .then(results => numbers.filter((_, index) => results[index])) | |
| // [4] |
This file contains hidden or 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 obj = { books: 10, ruler: 1, pencils: 5 } | |
| const add = (a, b) => a + b | |
| const total = Object.values(obj).reduce(add, 0) // 16 |
This file contains hidden or 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 obj = { books: 10, ruler: 1, pencils: 5 } | |
| const isEven = x => Promise.resolve(x % 2 === 0) |
This file contains hidden or 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 result = await Promise | |
| .all(numbers.map(isEven))) | |
| .then(results => numbers.filter((_, index) => results[index])) | |
| // [4] |
NewerOlder