This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "bytes" | |
func StreamToByte(stream io.Reader) []byte { | |
buf := new(bytes.Buffer) | |
buf.ReadFrom(stream) | |
return buf.Bytes() | |
} | |
func StreamToString(stream io.Reader) string { | |
buf := new(bytes.Buffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://codepen.io/taroyanaka/pen/bmxoMw?editors=0011 | |
const R = require('ramda'); | |
const permutations = (tokens, subperms = [[]]) => | |
R.isEmpty(tokens) ? | |
subperms : | |
R.addIndex(R.chain)((token, idx) => permutations( | |
R.remove(idx, 1, tokens), | |
R.map(R.append(token), subperms) | |
), tokens); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { has, path, propOr, pathOr, keys, values } from "ramda" | |
const one = { | |
a: "Bingo", | |
b: { | |
c: "Bingo", | |
}, | |
} | |
const two = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compose, both, either, gte, prop, equals, __ } from "ramda" | |
const OUR_COUNTRY = "France" | |
const wasBornInCountry = compose( | |
equals(OUR_COUNTRY), | |
prop("birthCountry"), | |
) | |
const wasNaturalized = compose( | |
Boolean, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { assoc, assocPath, dissoc, dissocPath, omit, compose, inc, prop } from "ramda" | |
const original = { | |
a: "Bingo", | |
b: { | |
c: "Bingo", | |
d: "Bingo", | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
nth, | |
slice, | |
contains, | |
head, | |
last, | |
tail, | |
init, | |
length, | |
take, |
OlderNewer