Skip to content

Instantly share code, notes, and snippets.

@azu
azu / README.md
Last active March 15, 2024 09:59
スタートアップ/企業の調べ方
@mattn
mattn / fizzbuzz.go
Last active November 3, 2018 03:27
learn FizzBuzz with gobrain
package main
import (
"math/rand"
"github.com/goml/gobrain"
)
type FizzBuzz []float64
@sebabouche
sebabouche / ramda8.js
Created June 22, 2018 20:22
ramda: lens (lens, lensProp, lensPath, view, set, over)
import { lensProp, lensPath, view, set, over, toUpper } from "ramda"
const me = {
firstName: "Sébastien",
lastName: "Nicolaïdis",
birthDate: new Date("1979-09-13T15:00Z"),
age: 38,
hobbies: ["Rock climbing", "Horse riding", "Chess"],
parents: {
brother: {
@sebabouche
sebabouche / ramda7.js
Created June 22, 2018 20:21
ramda: arrays (nth, slice, contains, head, last, tail, init...)
import {
nth,
slice,
contains,
head,
last,
tail,
init,
length,
take,
@sebabouche
sebabouche / ramda6.js
Last active October 24, 2018 02:39
ramda: objects (compose, inc, prop, assoc, evolve, always, add)
import { compose, inc, prop, assoc, evolve, always, add } from "ramda"
const nextAge = compose(
inc,
prop("age"),
)
console.log("nextAge", nextAge({ age: 21 }))
const celebrateBirthday = person => assoc("age", nextAge(person), person)
const person = { age: 24 }
console.log("celebrateBirthday", celebrateBirthday(person))
@sebabouche
sebabouche / ramda5.js
Created June 22, 2018 20:19
ramda: assoc, assocPath, dissoc, dissocPath, omit, compose, inc, prop
import { assoc, assocPath, dissoc, dissocPath, omit, compose, inc, prop } from "ramda"
const original = {
a: "Bingo",
b: {
c: "Bingo",
d: "Bingo",
},
}
@sebabouche
sebabouche / ramda4.js
Created June 22, 2018 20:18
ramda: has, path, propOr, pathOr, keys, values
import { has, path, propOr, pathOr, keys, values } from "ramda"
const one = {
a: "Bingo",
b: {
c: "Bingo",
},
}
const two = {
@sebabouche
sebabouche / ramda3.js
Created June 22, 2018 20:17
ramda: cond, always, T, identity
import { cond, always, lte, gte, T, __, identity } from "ramda"
const water = cond([
[lte(__, 0), temp => `water freezes at ${temp}°C`],
[gte(__, 100), temp => `water boils at ${temp}°C`],
[T, temp => `nothing special happens at ${temp}°C`],
])
console.log(water(-222))
@sebabouche
sebabouche / ramda2.js
Created June 22, 2018 20:16
ramda: ifElse, gte, lt, always, identity, whn, unless
import { ifElse, gte, lt, __, always, identity, when, unless } from "ramda"
// const forever21 = age => (age >= 21 ? 21 : age)
// const forever21 = ifElse(gte(__, 21), always(21), identity)
// const forever21 = unless(lt(__, 21), always(21))
const forever21 = when(gte(__, 21), always(21))
console.log("forever21(24)", forever21(24))
console.log("forever21(16)", forever21(16))
@sebabouche
sebabouche / ramda1.js
Created June 22, 2018 20:16
ramda: map, filter, partial, partialRight, curry, __, pipe
import { map, filter, partial, partialRight, curry, __, pipe } from "ramda"
const publishedInYear = curry((year, book) => book.year === year)
const titlesForYear = curry((year, books) =>
pipe(
filter(publishedInYear(year)),
map(book => book.title),
)(books),
)