Skip to content

Instantly share code, notes, and snippets.

View piq9117's full-sized avatar
๐Ÿ’€
Nothing good is happening here

piq9117 piq9117

๐Ÿ’€
Nothing good is happening here
View GitHub Profile
const devs = {
'developer1': {
name: 'ken',
hairColor: 'black',
iceCreamFlavor: '',
favoriteFood: [
'apple',
'chips',
'car'
]
function addFood (state, action) {
// favoriteFood :: {k: v} -> {k: v}
const favoriteFood = favorite => Object.assign({}, {favoriteFood: []}, favorite)
// food :: {k: v} -> {k: v}
const food = favoriteFood(
Object.assign({}, state[action.data.id], {
[action.data.prop]: state[action.data.id].favoriteFood.concat(action.data.food)
})
)
function addFood (state, action) {
// favoriteFood :: {k: v} -> {k: v}
/*
Reading from the left, this means:
The name of the function,
it takes a {key: value} pair which is an object in javascript,
then returns a {key: value} pair; let's call it the Food type.
*/
const favoriteFood = food => Object.assign({}, {favoriteFood: []}, food)

Preface: All ramda functions are curried.

// split :: (String | RegExp) -> String -> [String]

Split takes in a String or RegExp as a separator, in this case I only gave it the quotation marks which will serve as the separator; it will split the string into letters. Since this function is curried I can provide the String later on.

// addProps :: {k: v} -> {k: v}
const addProps = props => Object.assign({}, {iceCreamFlavor: '', favoriteFood: []}, props)
function addFood (state, action) {
// food :: Food
const food = addProps(Object.assign({}, state[action.data.id], {
[action.data.prop]: state[action.data.id].favoriteFood.concat(action.data.food)
}))
// assocPath :: [String] -> {k: v} -> {k: v} -> {k: v}
return R.assocPath([action.data.id])(food)(state)
// addProps :: {k: v} -> {k: v}
const addProps = props => Object.assign({}, {iceCreamFlavor: '', favoriteFood: []}, props)
function iceCreamFlavor (state, action) {
// flavor :: Flavor
const flavor = addProps(Object.assign({}, state[action.data.id], {
[action.data.prop]: action.data.flavor
}))
return R.assocPath([action.data.id])(flavor)(state)
}
'use strict'
/* global describe, it */
import { expect } from 'chai'
import reducer from './index'
const initialState = {
'developer1': {
name: 'ken',
hairColor: 'black',
@piq9117
piq9117 / ngrxintro.md
Created September 14, 2016 23:49 — forked from btroncone/ngrxintro.md
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

#Comprehensive Introduction to @ngrx/store By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@piq9117
piq9117 / Maybe.ts
Last active May 8, 2017 03:07 — forked from co1rowjp/gist:3845888
TypeScript Maybe
interface Functor {
fmap: (any) => any;
}
interface Monad extends Functor {
bind: (any) => Monad;
}
interface Maybe extends Monad {
}
@piq9117
piq9117 / Monad-maybe.ts
Last active May 8, 2017 03:08 — forked from co1rowjp/gist:4252025
TypeScript Maybe(I want pattern match..)
interface Functor {
fmap: (any) => any;
}
interface Monad extends Functor {
bind: (any) => Monad;
}
interface MaybeMatcher {
just: (any) => Maybe;