Less boilerplate when create a new reducer on Redux
Method:
'use strict'
const createReducer = (initialState, actionHandlers) => {
const compose = (...fns ) => fns.reduce( ( f, g ) => (...args ) => f( g(...args ) ) ) |
/* | |
Hoje iremos MUDAR a vida da pessoa que não te responde no whatsappp... | |
Que tal enviar mensagens pra ela até obter uma resposta?! | |
Sensacional não acha?! Mas, somos devs, correto?! Então vamos automatizar esse paranauê! | |
Para utilizar: | |
- Abra o web.whatsapp.com; | |
- Selecione a conversa que você quer; | |
- Abra o console e cole o código que está no gist; |
const add = ( x ) => ( y ) => x + y | |
const divide = ( x ) => ( y ) => { | |
let multiplyfor10 = 0; | |
const multiply10 = add(10) | |
const decrement1 = add(-1) | |
const addFinal = add(0.1) | |
const decrementY = add(-y) |
Create a cond
function that takes 2 arguments:
[
[firstCondition, firstCallback],
[secondCondition, secondCallback],
...
]
const getDataFromInscricao = ( inscricao ) => [ | |
inscricao.substr( inscricao.length - 2, 2 ), | |
inscricao.substr( inscricao.length - 4, 2 ), | |
inscricao.substr( 0, inscricao.length - 2 ) | |
] | |
const calcSum1 = ( titulo ) => | |
titulo.substr( 0, 8 ).split( '' ).reduce( ( total, val, i ) => total += val * ( 9 - i ), 0 ) | |
const fixDigit = ( exce ) => ( dig ) => |
//Mais simples possível | |
fun isPrime(num:Int) :Boolean { | |
if ((num % 2) == 0 && num !== 2 || num == 1) { | |
print("Não é primo") | |
return false | |
} | |
const pairwise = (arr, arg) => | |
/* | |
Primeiro laço (reduce) com os numeros recebidos no array | |
Inicio o reduce com um array contendo 2 posições, um número inteiro que vai armazenar as somas dos indices e um | |
objeto que vai armazenar os indices já usados no processo | |
*/ | |
arr.reduce((acc, cur, indexR, arr) => { | |
/* | |
Segundo laço (forEach) para testar o valor recebido do reduce com cada valor do array com a finalizade de | |
satisfazer a condição do desafio |
-export([uptime/0, uptime/1, uptime_string/0]). | |
%% @doc uptime in native time units | |
uptime() -> | |
erlang:monotonic_time() - erlang:system_info(start_time). | |
%% @doc uptime in specified time units | |
uptime(Unit) -> | |
erlang:convert_time_unit(uptime(), native, Unit). |
/* | |
* imap lazily maps an interable. | |
* @param fn Map function | |
* @param iterableOrIterator Either an iterable or an iterator | |
* | |
* It works by always returning a new iterator so that | |
* you can chain other imaps without loopin once more | |
* over the same array! | |
* | |
* Since iterables are returned, to start the real mapping |