= function(outro) { this.gaivotas += outro.gaivotas; return this; }; Rebanho.prototype.procriar = function(outro) { this.gaivotas = this.gaivotas * outro.gaivotas; return this; }; var rebanho_a = new Rebanho(4); var rebanho_b = new Rebanho(2); var rebanho_c = new Rebanho(0); var result = rebanho_a.unir(rebanho_c) .procriar(rebanho_b).unir(rebanho_a.procriar(rebanho_b)).gaivotas; Orientado a Objetos
the identity property to remove the extra add // (add(flock_a, flock_c) == flock_a) add(multiply(flock_b, flock_a), multiply(flock_a, flock_b)); // Apply distributive property to achieve our result multiply(flock_b, add(flock_a, flock_a));
inserção de registro no banco de dados • fazer uma chamada HTTP • mutations • imprimir alguma informação na tela / logging • obtenção de input do usuário • querying o DOM (querySelector)
implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana... and the entire jungle" ~> Erlang creator, Joe Armstrong
last = compose(head, reverse); var loudLastUpper = compose(exclaim, toUpperCase, last); // ou var last = compose(head, reverse); var angry = compose(exclaim, toUpperCase); var loudLastUpper = compose(angry, last); // n possibilidades...
}); var dasherize = compose(join('-'), toLower, split(' '), replace(/\s{2,}/ig, ' ')); dasherize('The world is a vampire'); // TypeError: Cannot read property 'apply' of undefined
da palavra-chave; 2. Fazer uma chamada HTTP à API do Flickr; 3. Transformar o resultado JSON em HTML images; 4. Renderiza-los na tela; https://api.flickr.com/services/feeds/photos_public.gne?tags =cats&format=json&jsoncallback=?
-> Either(String, Number) var getAge = curry(function(now, user) { var birthdate = moment(user.birthdate, 'YYYY-MM-DD'); if (!birthdate.isValid()) return Left.of('Birth date could not be parsed'); return Right.of(now.diff(birthdate, 'years')); }); getAge(moment(), { birthdate: '2005-12-12', }); // Right(9) getAge(moment(), { birthdate: '20010704', }); // Left('Birth date could not be parsed')
you survive, you will be '), add(1)); // zoltar :: User -> Either(String, _) var zoltar = compose(map(console.log), map(fortune), getAge(moment())); zoltar({ birthdate: '2005-12-12', }); // 'If you survive, you will be 10' // Right(undefined) zoltar({ birthdate: 'balloons!', }); // Left('Birth date could not be parsed')
-> Either a b -> c var either = curry(function(f, g, e) { switch (e.constructor) { case Left: return f(e.__value); case Right: return g(e.__value); } }); // zoltar :: User -> _ var zoltar = compose(console.log, either(id, fortune), getAge(moment())); zoltar({ birthdate: '2005-12-12', }); // "If you survive, you will be 10" // undefined zoltar({ birthdate: 'balloons!', }); // "Birth date could not be parsed" // undefined