Skip to content

Commit

Permalink
9.1.1 faster equals with Object.is short circuit (#727)
Browse files Browse the repository at this point in the history
* chore@small

* chore@small
  • Loading branch information
selfrefactor committed Mar 11, 2024
1 parent 2b31fca commit 12ce01a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,8 @@ function parseRegex(maybeRegex){
export function equals(a, b){
if (arguments.length === 1) return _b => equals(a, _b)

if (Object.is(a, b)) return true

const aType = type(a)

if (aType !== type(b)) return false
Expand Down Expand Up @@ -4554,7 +4556,7 @@ describe('brute force', () => {
{
"ERRORS_MESSAGE_MISMATCH": 0,
"ERRORS_TYPE_MISMATCH": 0,
"RESULTS_MISMATCH": 8,
"RESULTS_MISMATCH": 0,
"SHOULD_NOT_THROW": 0,
"SHOULD_THROW": 0,
"TOTAL_TESTS": 289,
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3925,6 +3925,8 @@ function parseRegex(maybeRegex){
export function equals(a, b){
if (arguments.length === 1) return _b => equals(a, _b)

if (Object.is(a, b)) return true

const aType = type(a)

if (aType !== type(b)) return false
Expand Down Expand Up @@ -4329,7 +4331,7 @@ describe('brute force', () => {
{
"ERRORS_MESSAGE_MISMATCH": 0,
"ERRORS_TYPE_MISMATCH": 0,
"RESULTS_MISMATCH": 8,
"RESULTS_MISMATCH": 0,
"SHOULD_NOT_THROW": 0,
"SHOULD_THROW": 0,
"TOTAL_TESTS": 289,
Expand Down
8 changes: 4 additions & 4 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6979,8 +6979,8 @@ Notes:
*/
// @SINGLE_MARKER
export function mapToObject<T, U>(fn: (input: T) => object|false, list: T[]): U;
export function mapToObject<T, U>(fn: (input: T) => object|false): (list: T[]) => U;
export function mapToObject<T, U extends object>(fn: (input: T) => U|false, list: readonly T[]): U;
export function mapToObject<T, U extends object>(fn: (input: T) => U|false): (list: readonly T[]) => U;

/*
Method: mapToObjectAsync
Expand All @@ -6999,8 +6999,8 @@ Notes:
*/
// @SINGLE_MARKER
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<object|false>, list: T[]): Promise<U>;
export function mapToObjectAsync<T, U>(fn: (input: T) => Promise<object|false>): (list: T[]) => Promise<U>;
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>, list: readonly T[]): Promise<U>;
export function mapToObjectAsync<T, U extends object>(fn: (input: T) => Promise<U|false>): (list: readonly T[]) => Promise<U>;

/*
Method: mapKeys
Expand Down
14 changes: 5 additions & 9 deletions src/unless.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { curry } from './curry.js'
export function unless(predicate, whenFalse){
if (arguments.length === 1){
return _whenFalse => unless(predicate, _whenFalse)
}

function unlessFn(
predicate, whenFalseFn, input
){
if (predicate(input)) return input

return whenFalseFn(input)
return input => predicate(input) ? input : whenFalse(input)
}

export const unless = curry(unlessFn)

0 comments on commit 12ce01a

Please sign in to comment.