Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
Teaching people 🔥🦩 LiveView 🔥🦩

Lubien lubien

💭
Teaching people 🔥🦩 LiveView 🔥🦩
View GitHub Profile
@lubien
lubien / 1. intro.md
Last active January 7, 2020 00:16
Cond

Create a cond function that takes 2 arguments:

  1. An matrix in the format:
[
  [firstCondition, firstCallback],
  [secondCondition, secondCallback],
  ...
]
@lubien
lubien / imap-islice.js
Created June 24, 2017 18:08
Proof of concept of lazy evaluation of map and slices on JavaScript using generators, iterables and iterators. https://repl.it/JAbL/1
/*
* imap lazily maps an interable.
* @param ref Either an iterable or an iterator
* @param fn Map function
*
* It works by always returning a new iterator so that
* you can chain other imaps without looping once more
* over the same array!
*
* Since iterators are returned, to start the real mapping
@lubien
lubien / validate-posts.js
Created June 24, 2017 06:05
Meeting Lambda #13: Quantification - Validate Posts
const validPost = post =>
post.title && post.title.length > 10 && post.content
const posts =
[ {title: 'short'}
, {title: 'fairly long', content: 'Foobar'}
, {title: 'yet another', content: 'fixture'}
]
const validPosts = posts.every(validPost)
@lubien
lubien / prime-quantifier.js
Last active June 24, 2017 05:59
Meeting Lambda #13: Quantification - Prime
const range = (start, end) =>
Array.from({length: end - start}, (_, i) => start + i)
const divides = x => y =>
x % y === 0
const prime = n => {
if (n < 2)
return false
if (n === 2)
@lubien
lubien / has-integer-log.js
Created June 24, 2017 05:28
Meeting Lambda #12: Quantification - Has Integer? Log
const checkAndLog = x => {
console.log('passed by', x)
return Number.isInteger(x)
}
const xs = ['a', 1, 2, 3, 4]
const ys = ['a', 'b', 'c', 'd', 'e']
const xsHasinteger = xs.some(checkAndLog)
// passed by a
@lubien
lubien / are-all-integers-log.js
Last active June 24, 2017 05:24
Meeting Lambda #12: Quantification - Are All Integers? Log
const checkAndLog = x => {
console.log('passed by', x)
return Number.isInteger(x)
}
const xs = [1, 2, 3, 4, 5]
const ys = [6, 7, 'a', 9, 10]
const areXsIntegers = xs.every(checkAndLog)
// passed by 1
@lubien
lubien / has-integer.js
Created June 24, 2017 05:18
Meeting Lambda #12: Quantification - Has Integer?
const xs = ['a', 'b', 'c', 'd', 5]
const ys = ['a', 'b', 'c', 'd', 'e']
const xsHasinteger = xs.some(Number.isInteger)
const ysHasinteger = ys.some(Number.isInteger)
console.log(xsHasinteger) // true
console.log(ysHasinteger) // false
@lubien
lubien / are-all-integers.js
Created June 24, 2017 05:16
Meeting Lambda #12: Quantification - Are All Integers?
const xs = [1, 2, 3, 4, 5]
const ys = [1, 2, 'a', 4, 5]
const areXsIntegers = xs.every(Number.isInteger)
const areYsIntegers = ys.every(Number.isInteger)
console.log(areXsIntegers) // true
console.log(areYsIntegers) // false
@lubien
lubien / sane-binary-functions.js
Created June 24, 2017 03:27
Meeting Lambda #12: Curry or Partial? - Sane Binary Functions
const add = (x, y) => x + y
const sub = (x, y) => x - y
console.log('10 + 3 - 4 =', sub( add(10, 3), 4 ) )
@lubien
lubien / why-did-u-even-curry.js
Created June 24, 2017 03:20
Meeting Lambda #12: Curry or Partial? - Why Did You Even Curry?
const add = x => y => x + y
const sub = x => y => x - y
console.log('10 + 3 - 4 =', sub( add(10)(3) )(4) )