Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Ramda works with $ReadOnlyArray as it is immutable.
const readOnlyArray: $ReadOnlyArray = [1, 2, 3, 4];
// $ReadOnlyArray with curried permutations:
const redxsReadOnly3: number = reduce(subtract, 0, readOnlyArray);
const redxsReadOnly2_1: number = reduce(subtract, 0)(readOnlyArray);
const redxsReadOnly1_2: number = reduce(subtract)(0, readOnlyArray);
const redxsReadOnly1_1_1: number = reduce(subtract)(0)(readOnlyArray);
// $ExpectError reduce will not work with an object.
reduce(subtract, 0, { foo: 1, bar: 2 });
// reduceRight
const redrxs1: number = _.reduceRight(_.add, 10, ns);
const redrxs2: string = _.reduceRight(_.concat, "", ss);
const redrxs3: Array = _.reduceRight(_.concat, [])(
_.map(x => [x], ss)
);
const redrxs3a: string = _.reduceRight(
//$ExpectError
(acc: string, value: number): string => acc,
"",
ns
);
const redrxs3b: string = _.reduceRight(
(value: number, acc: string): string => acc,
"",
ns
);
// $ExpectError reduceRight does not support reduced.
const redrxs4: number = _.reduceRight(
// $ExpectError reduceRight does not support reduced.
const someObj: { a: string, b: number } = { a: 'a', b: 2 }
const someMap: { [string]: { a: string, b: number } } = { so: someObj }
const mapObj: { [string]: string } = _.map((x: { a: string, b: number }): string => x.a)(someMap)
const functor = {
x: 1,
map(f) {
return f(this.x)
},
}
// Doesn't typecheck (yet) but at least doesn't break
const mapFxs = _.map(_.toString, functor)
const double = x => x * 2
const dxs: Array = _.map(double, [ 1, 2, 3 ])
const dos: $Shape = _.map(double, obj)
const appender = (a, b) => [ a + b, a + b ]
const mapacc:[number, Array] = _.mapAccum(appender, 0, ns)
const mapacc1:[number, Array] = _.mapAccumRight(appender, 0, ns)
const nxs: boolean = _.none(x => x > 1, ns)
const nthxs: ?string = _.nth(2, [ 'curry' ])
const nthxs1: ?string = _.nth(2)([ 'curry' ])
//$ExpectError
const nthxs2: string = _.nth(2, [ 1, 2, 3 ])
const xxs: Array = _.append(1, [ 1, 2, 3 ])
const xxxs: Array = _.intersperse(1, [ 1, 2, 3 ])
function printTokens(lines) {
R.map(line => {
// FIXME: This will break when we move to lazy style parsing
let lineNo = lines.indexOf(line) + 1
console.log(" {
process.stdout.write(`<${token.name}>`)
}, line)
console.log("\n/>\n")
}, lines)
}
fs.readFile(fileName, "utf-8", (err, data) => {
// die quietly for we have failed
if (err) {
return
}
if (data && is(String, data)) {
try {
let lines
let lineCounter = 0
const lineBreak = /\n/g
const contents = split(lineBreak, data)
// create a new structure of lines
const sourceLines = map(line => {
lineCounter = lineCounter + 1
// i am sorry my tab-based brethern.
const source = replace(/\t/, " ", line)
return {
isSelected: lineCounter === lineNumber,
lineNumber: lineCounter,
source,
}
}, contents)
// should just load it all?
const showWholeFile = contents.length < SOURCE_LINES_UP + SOURCE_LINES_DOWN
if (showWholeFile) {
lines = sourceLines
} else {
emphasize,
uppercase,
sayHello
)({ name })
})
))
const footerView = yield footer2
// Combine everything together!
return Reader.of(headerView.concat(messageView).concat(footerView))
})
// Hmm, let's style the element as well!
const styledApp = app.map(
map(x => (
<div style="{{">{x}</div>
))
)
export default element => {
ReactDOM.render(
styledApp
.runReader({
color: 'green',
locale: 'zh',
title: 'Awesome App',
author: 'Bob McBob',
year: 2017
})
.fold({ name: 'Alice' }),
element
import { equals, filter, concat, map, complement } from 'ramda'
const isZero = equals(0)
const isTile = complement(isZero)
const filterZeroes = filter(isZero)
const filterTiles = filter(isTile)
export const shift = (board) => concat(filterZeroes(board), filterTiles(board))
// shift zero tiles to the top of the array
export const shiftBoard = map(shift)
}
const fields = R.pipe(
R.head,
R.keys,
R.reject(R.equals(ref)),
)(documents)
const index = lunr(function() {
this.ref(ref)
fields.forEach(x => this.field(x))
documents.forEach(x => this.add(x))
})
const store = R.pipe(
R.map(R.pick(storeFields)),
R.indexBy(R.prop(ref)),
)(documents)
R.pipe(
createNodeFactory(name),
createNode,
)({
id: name,
index: JSON.stringify(index),
store: JSON.stringify(store),
})
return
}
([key, value]) =>
is(Object, value) ? map(concat([key]), pathsIn(value)) : [[key]],
toPairs(obj)
linkData() {
const { links, values } = this.props;
return map(({ onClick, title }) => {
return { onClick: () => onClick(values), title };
}, links);
}
const ramdaTransducerInfiniteBenchmark = xs => R.into([], R.compose(
R.map(add10),
R.map(triple),
R.filter(divisibleBy5),
R.filter(isEven),
R.take(length),
), xs)