Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.1.1 faster equals with Object.is short circuit #727

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading