Skip to content

Instantly share code, notes, and snippets.

View DanShappir's full-sized avatar

Dan Shappir DanShappir

  • Wix
View GitHub Profile
@DanShappir
DanShappir / lean_find.js
Last active December 4, 2019 16:44
Lean code for implementing find
const largeNumber = numbers // Can also be written simply as: find(numbers, v => v > 42);
|> find(#, v => v > 42);
@DanShappir
DanShappir / find.js
Created November 6, 2019 12:34
Simple find function
function find(src, op) {
return src
|> filter(#, op)
|> head;
}
@DanShappir
DanShappir / find_example.js
Created November 6, 2019 12:35
Example of using find function
const largeNumber = numbers
|> find(#, v => v > 42);
@DanShappir
DanShappir / declarative_double.js
Created November 7, 2019 09:08
Double values of items in an array using declarative approach
const doubled = numbers.map(v => 2 * v); // numbers is an array
@DanShappir
DanShappir / imperative_double.js
Created November 7, 2019 09:10
Double values of items in an array using imperative approach
const doubled = [];
for (const v of numbers) {
doubled.push(2 * v);
}
const largeNumber = numbers
|> filter(#, v => v > 42)
|> head;
for (const item of collection) {
console.log(item);
}
forEach(collection, item => console.log(item));
for await (const event of sequence) {
console.log(event);
}
const wait = (value, delay = 1000) => new Promise(resolve => setTimeout(() => resolve(value), delay));
const timedSequence = {
[Symbol.asyncIterator]() {
let count = 0;
return {
next() {
return wait({
value: count++,
done: count > 10