Skip to content

Instantly share code, notes, and snippets.

🌶
Working from home

Sam Slotsky sslotsky

🌶
Working from home
Block or report user

Report or block sslotsky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View debounced-promise.js
function debounce(fn, interval) {
let timeout;
return function(...args) {
clearTimeout(timeout);
return new Promise(resolve => {
timeout = setTimeout(() => resolve(fn(...args)), interval);
});
}
}
View augment.re
let (>>=) = (m: chainableList('a), f: list('a) => chainableList('b)) => {
switch(m) {
| Value(l) => doSomeStuffAndReturn(l |> f)
| Failure => logThisFailure(m); Failure
}
};
View fluentList.re
/* Fluent list operations in ReasonML */
let l = return([1, 2, 3])
>>= wrap(List.map(n => n * 2))
>>= wrap(List.filter(n => n mod 2 != 0))
>>= tail;
View neverFails.re
let return = x => Value(x);
let wrap = (f, l) => return(l |> f);
View bind.re
let (>>=) = (m: chainableList('a), f: list('a) => chainableList('b)) => switch(m) {
| Value(l) => l|> f
| Failure => Failure
};
View tailWrapper.re
let tail = x => switch(x |> List.tl) {
| l => Value(l)
| exception _ => Failure
};
View listWrapper.re
type chainableList('a) =
| Value(list('a))
| Failure;
View tailFail.re
let l = [1, 2, 3]
|> List.map(n => n * 2)
|> List.filter(n => n mod 2 != 0)
|> List.tl;
View mapAndFilter.re
let selection = [1, 2, 3]
|> List.map(n => n * 3)
|> List.filter(n => n mod 2 == 0);
View map.re
let integers = [1, 2, 3];
let multiples = integers |> List.map(n => n * 3);
You can’t perform that action at this time.