Skip to content

Instantly share code, notes, and snippets.

View WaldoJeffers's full-sized avatar
🤓
Building a new standard JS library: conductor

WaldoJeffers

🤓
Building a new standard JS library: conductor
View GitHub Profile
@WaldoJeffers
WaldoJeffers / index.js
Created May 15, 2018 14:08
expectToThrow
import { identity, map, compose, forEach } from 'ramda'
const withCatchAll = fn => (...args) => fn(...args).catch(identity)
const unsafeInsert = witchCatchAll(insert)
await Promise.all(map(compose(unsafeInsert, stripOneMandatoryParam)), MANDATORY_PARAMS).then(forEach(expectToThrow))
const obj = { books: 10, ruler: 1, pencils: 5 }
{
Alderaan: {
brown: 1
},
Naboo: {
red: 1
},
Stewjon: {
'blue-gray': 1,
Tatooine: {
const character_ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
import { reduce } from 'conductor'
const homeworld_stats = reduce(reducer, character_ids)
// { Alderaan: 1, Naboo: 1, Stewjon: 1, Tatooine: 7 }
import { compose, get } from 'conductor'
const getHomeworldName = compose(get('name'), fetchJSON, get('homeworld'), fetchCharacter)
// getHomeworldName(1) == { name: 'Tatooine', ... }
import { compose } from 'conductor'
const countHomeworld = compose(countOne, getHomeworldName)
// countHomeworld(1) == { Tatooine: 1 }
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' }, ...]
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' }, ...]
import { map } from 'conductor'
const numbers = [1, 2, 3]
const add1 = x => x + 1
map(add1)(numbers) // == map(add1, numbers) == [2, 3, 4]