Rodolfo Hansen
A collection of slides I have generated for some of the talks / workshops I have created.
Getters y Setters correctamente
var game =
{
start: new Date(),
board: {
cells: [{c: 0, d: 1}, {c: 1, d: 2}, {c: 0, d: 1}, {c: 1, d: 1}],
captures: [{c: 1}, {c: 1}],
},
player: {
name: "John",
lives: 3,
stats: {
wins: 1,
high_score: 123
}
}
}
game.player.stats.wins++
Que esta mal aquí?
import Task from 'data.task'
import Maybe from 'data.maybe'
import {lensProp, lensIndex,compose, map, toUpper, reverse, replace} from 'ramda'
import {mapped, over, view, set, lens, iso, from} from 'ramda-lens'
import {Map, List} from 'immutable'
const user = {id: 3, name: 'Pedro Sanchez', addresses: [
{street: 'Calle 5', zip: '04821'},
{street: 'Ave. 27 de Febrero', zip: '08082'}
]}
const name = lensProp('name')
view(name, user)
// Pedro Sanchez
set(name, 'Juan Guzman', user)
// { id: 3, name: 'Juan Guzman', ...
over(name, toUpper, user)
// { id: 3, name: 'PEDRO SANCHEZ', ...
Get, Set, Map
const user = {id: 3, name: 'Pedro Sanchez', addresses: [
{street: 'Calle 5', zip: '04821'},
{street: 'Ave. 27 de Febrero', zip: '08082'}
]}
const first = lensIndex(0)
const firstStreet = compose(addresses, first, street)
view(firstStreet, user)
// 99 Walnut Dr.
over(firstStreet, reverse, user)
// ???
Composición
const arrayIso = iso(x => x.toJS(), x => List.of.apply(List, x))
// spliceAndReturn :: [a] -> [a]
const spliceAndReturn = xs => {
xs.splice(0,1)
return xs
}
over(arrayIso, spliceAndReturn, List.of(1,2,3,4,5))
// List [2,3,4,5]
//
over(from(arrayIso), x => x.take(1), [1,2,3,4,5])
// [1]
Iso
Rodolfo Hansen @kryptt
By Rodolfo Hansen
Getters y Setters correctamente
A collection of slides I have generated for some of the talks / workshops I have created.