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 { compose, head, split, get } from 'conductor' | |
const character = {name: 'Luke Skywalker'} | |
const getFirstName = compose(head, split(' '), get('name')) | |
getFirstName(character) // 'Luke' |
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 { map } from 'conductor' | |
const add1 = x => x + 1 | |
const mapByAdding1 = map(add1) // == collection => map(add1, collection) | |
mapByAdding1([1, 2, 3]) // [2, 3, 4] | |
mapByAdding1([2, 0, 3]) // [3, 1, 4] |
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 { map } from 'conductor' | |
const numbers = [1, 2, 3] | |
const add1 = x => x + 1 | |
map(add1)(numbers) // == map(add1, numbers) == [2, 3, 4] |
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 { filter } from 'conductor' | |
const obj = { books: 10, ruler: 1, pencils: 5 } | |
const isEven = x => x % 2 === 0 | |
filter(isEven, obj) // { books: 10 } |
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 { compose, equals, filter, get } from 'conductor' | |
const character_ids = [1, 2, 3, 4, 5] | |
const fetchCharacter = id => fetch(`https://swapi.co/api/people/${id}`).then(res => res.json()) | |
const hasBlueEyes = compose(equals('blue'), get('eye_color'), fetchCharacter)) | |
await filter(hasBlueEyes, characters_ids) // [{ name: 'Luke Skywalker }, { name: 'Owen Lars' }, ...] |
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 { map } from 'conductor' | |
const character_ids = [1, 2, 3, 4, 5] | |
const fetchCharacter = id => fetch(`https://swapi.co/api/people/${id}`).then(res => res.json()) | |
await map(fetchCharacter, characters_ids) // [{ name: 'Luke Skywalker }, { name: 'C-3PO' }, ...] |
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 { reduce } from 'conductor' | |
const homeworld_stats = reduce(reducer, character_ids) | |
// { Alderaan: 1, Naboo: 1, Stewjon: 1, Tatooine: 7 } |
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 reducer = (acc, character_id) => getHomeworldName(character_id) | |
.then(mergeByAdding(acc)) | |
// reducer({ Tatooine: 1 }, 3) == { Naboo: 1, Tatooine: 1 } |
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 { add, mergeWith } from 'conductor' | |
const mergeByAdding = mergeWith(add) | |
// mergeByAdding({ Alderaan: 1, Tattooine: 2 }, { Tattooine: 1 }) | |
// == { Alderaan: 1, Tattooine: 3 } |
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 { compose } from 'conductor' | |
const countHomeworld = compose(countOne, getHomeworldName) | |
// countHomeworld(1) == { Tatooine: 1 } |