-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
905 additions
and
63 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expectType } from 'ts-expect' | ||
|
||
import { A, pipe } from '../..' | ||
|
||
const xs = [1, 2, 3, 4, 5, 6, 7] | ||
|
||
// TODO: expectType | ||
describe('dropWhile', () => { | ||
it('drops elements from the beginning of the array until an element is reached which does not satisfy the given predicate', () => { | ||
const result = A.dropWhile(xs, x => x < 4) | ||
expect(result).toEqual([4, 5, 6, 7]) | ||
}) | ||
|
||
it('returns correct array elements if either true or false', () => { | ||
expect(A.dropWhile(xs, _x => true)).toEqual([]) | ||
expect(A.dropWhile(xs, _x => false)).toEqual([1, 2, 3, 4, 5, 6, 7]) | ||
}) | ||
}) | ||
|
||
describe('dropWhile (pipe)', () => { | ||
it('drops elements from the beginning of the array until an element is reached which does not satisfy the given predicate', () => { | ||
const result = pipe( | ||
xs, | ||
A.dropWhile(x => x < 4), | ||
) | ||
expect(result).toEqual([4, 5, 6, 7]) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expectType } from 'ts-expect' | ||
|
||
import { A, pipe } from '../..' | ||
|
||
const xs = [1, 2, 3, 4, 5, 6, 7] | ||
|
||
// TODO: expectType | ||
describe('splitEvery', () => { | ||
it('returns an array of arrays, where each of the inner arrays has length equal to `n`', () => { | ||
const result = A.splitEvery(xs, 3) | ||
expect(result).toEqual([[1, 2, 3], [4, 5, 6], [7]]) | ||
}) | ||
|
||
it('returns the original array inside a new array if n is out of range', () => { | ||
expect(A.splitEvery(xs, 0)).toEqual([[1, 2, 3, 4, 5, 6, 7]]) | ||
expect(A.splitEvery(xs, 8)).toEqual([[1, 2, 3, 4, 5, 6, 7]]) | ||
}) | ||
}) | ||
|
||
describe('splitEvery (pipe)', () => { | ||
it('returns an array of arrays, where each of the inner arrays has length equal to `n`', () => { | ||
const result = pipe(xs, A.splitEvery(3)) | ||
expect(result).toEqual([[1, 2, 3], [4, 5, 6], [7]]) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expectType } from 'ts-expect' | ||
|
||
import { A, pipe } from '../..' | ||
|
||
const xs = [1, 2, 3, 4, 5, 6, 7] | ||
|
||
// TODO: expectType | ||
describe('takeWhile', () => { | ||
it('returns a new array, filled with elements from the provided array until an element does not pass the provided predicate', () => { | ||
const result = A.takeWhile(xs, x => x < 4) | ||
expect(result).toEqual([1, 2, 3]) | ||
}) | ||
|
||
it('returns correct array elements if either true or false', () => { | ||
expect(A.takeWhile(xs, _x => true)).toEqual([1, 2, 3, 4, 5, 6, 7]) | ||
expect(A.takeWhile(xs, _x => false)).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('takeWhile (pipe)', () => { | ||
it('returns a new array, filled with elements from the provided array until an element does not pass the provided predicate', () => { | ||
const result = pipe( | ||
xs, | ||
A.takeWhile(x => x < 4), | ||
) | ||
expect(result).toEqual([1, 2, 3]) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const Benchr = require('benchr') | ||
|
||
const files = process.argv.slice(2) | ||
|
||
const runner = new Benchr( | ||
{ | ||
reporter: './reporter.markdown.js', | ||
}, | ||
files, | ||
) | ||
|
||
runner.run() |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// https://github.com/robertklep/node-benchr/blob/master/lib/reporters/console.js | ||
|
||
const Table = require('easy-table') | ||
const path = require('path') | ||
|
||
module.exports = runner => { | ||
runner | ||
.on('run.start', file => {}) | ||
.on('run.complete', file => {}) | ||
.on('file.start', file => { | ||
const basename = path.basename(file, '.js') | ||
process.stdout.write(`### ${basename}\n\n`) | ||
}) | ||
.on('file.complete', file => {}) | ||
.on('suite.start', suite => { | ||
console.log(`_${suite.name.trim()}_`) | ||
}) | ||
.on('suite.cycle', suite => {}) | ||
.on('error', err => { | ||
console.error(err) | ||
}) | ||
.on('suite.complete', suite => { | ||
const fastest = suite.filter('fastest') | ||
const successful = suite.filter('successful') | ||
const table = new Table() | ||
|
||
suite.forEach(function (bench) { | ||
if (bench.aborted) { | ||
table.cell('status', '×') | ||
} else { | ||
table.cell('status', '✔') | ||
} | ||
table.cell('name', bench.name) | ||
if (bench.aborted) { | ||
table.cell('hz', 'ABORTED') | ||
} else { | ||
table.cell( | ||
'hz', | ||
bench.hz | ||
.toFixed(2) | ||
.toString() | ||
.replace(/\B(?=(\d{3})+\b)/g, ','), | ||
Table.padLeft, | ||
) | ||
table.cell('label', 'ops/sec') | ||
table.cell('rme', '±' + bench.stats.rme.toFixed(2) + '%') | ||
table.cell('runs', '(' + bench.stats.sample.length + ' runs)') | ||
|
||
// Show percentual difference between this benchmark and the fastest. | ||
if (fastest.length !== successful.length) { | ||
let diff = 'fastest' | ||
if (bench !== fastest[0]) { | ||
diff = | ||
'-' + ((1.0 - bench.hz / fastest[0].hz) * 100).toFixed(2) + '%' | ||
} | ||
table.cell('diff', diff) | ||
} | ||
} | ||
table.newRow() | ||
}) | ||
console.log('\n```bash\n' + table.print() + '```\n') | ||
if (successful.length > 1) { | ||
if (fastest.length === successful.length) { | ||
console.log('→ No discernible winner\n') | ||
} else { | ||
console.log('→ Fastest is **' + fastest.map('name') + '**\n') | ||
} | ||
} | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env sh | ||
|
||
mkdir -p ./.results | ||
|
||
results_file="./.results/results.md" | ||
|
||
rm -f $results_file | ||
|
||
glob_files=".*" | ||
|
||
complex=($(grep -HRl "$glob_files" ./complex)) | ||
|
||
for i in "${complex[@]}" | ||
do | ||
node "./index.markdown.js" "$i" 2>&1 | tee -a $results_file | ||
done | ||
|
||
simple=($(grep -HRl "$glob_files" ./simple)) | ||
|
||
for i in "${simple[@]}" | ||
do | ||
node "./index.markdown.js" "$i" 2>&1 | tee -a $results_file | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { | ||
makeBenchmark, | ||
addTsBelt, | ||
addLodashFp, | ||
addRambda, | ||
addRamda, | ||
addRemeda, | ||
} = require('../utils') | ||
|
||
const input = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
const fn = x => x < 5 | ||
|
||
module.exports = makeBenchmark( | ||
'dropWhile', | ||
addTsBelt(tsBelt => { | ||
const { A, pipe } = tsBelt | ||
|
||
return [ | ||
() => { | ||
return A.dropWhile(input, fn) | ||
}, | ||
() => { | ||
return pipe(input, A.dropWhile(fn)) | ||
}, | ||
] | ||
}), | ||
// addRemeda(remeda => { | ||
// const { pipe, dropWhile } = remeda | ||
|
||
// return [ | ||
// () => { | ||
// return dropWhile(input, fn) | ||
// }, | ||
// () => { | ||
// return pipe(input, dropWhile(fn)) | ||
// }, | ||
// ] | ||
// }), | ||
addRamda(ramda => { | ||
const { pipe, dropWhile } = ramda | ||
|
||
return [ | ||
() => { | ||
return dropWhile(fn, input) | ||
}, | ||
() => { | ||
return pipe(dropWhile(fn))(input) | ||
}, | ||
] | ||
}), | ||
addRambda(rambda => { | ||
const { pipe, dropWhile } = rambda | ||
|
||
return [ | ||
() => { | ||
return dropWhile(fn, input) | ||
}, | ||
() => { | ||
return pipe(dropWhile(fn))(input) | ||
}, | ||
] | ||
}), | ||
addLodashFp(_ => { | ||
return [ | ||
() => { | ||
return _.dropWhile(fn, input) | ||
}, | ||
() => { | ||
return _.pipe(_.dropWhile(fn))(input) | ||
}, | ||
] | ||
}), | ||
) |
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
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
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
Oops, something went wrong.