Skip to content

Instantly share code, notes, and snippets.

View marcog83's full-sized avatar

marco gobbi marcog83

  • https://plus.google.com/+marcogobbi0
  • milan
View GitHub Profile
@marcog83
marcog83 / validation.js
Last active May 25, 2018 12:54
Validation Create and Compose using 'folktale/validation' library
const {Success, Failure} = require('folktale/validation');
const create = (predicate, failure = _ => _) => {
return function (value) {
if (predicate(value)) {
return Success(value)
@marcog83
marcog83 / debouncePromise.js
Created April 20, 2018 14:32
debounce function that return Promise
function debouncePromise(inner, ms) {
ms = ms || 0;
var timer = null;
var resolves = [];
return function () {
var args = [].slice.call(arguments, 0);
// Run the function after a certain amount of time
clearTimeout(timer);
timer = setTimeout(function () {
@marcog83
marcog83 / chunk.js
Last active November 7, 2019 12:13
chunk array elements over a predicate function
var data = [1, 2, 3, 13, 5, 6, 7, 8, 9, 10, 11];
var predicate = element => element % 2 === 0;
function chunk(predicate, data) {
return data.map(predicate).reduce((prev, curr, i, arr) => {
if (curr) {
if (prev.length) {
let first = prev[prev.length - 1][1];
prev.push([first, i + 1]);
} else {