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

export eqStrict #965

Closed
steida opened this issue Oct 8, 2019 · 3 comments · Fixed by #1133, distributeaid/chat-ui#11, jianhan/fp-lib#33 or jianhan/fp-lib#40
Closed

export eqStrict #965

steida opened this issue Oct 8, 2019 · 3 comments · Fixed by #1133, distributeaid/chat-ui#11, jianhan/fp-lib#33 or jianhan/fp-lib#40
Assignees
Milestone

Comments

@steida
Copy link
Contributor

steida commented Oct 8, 2019

Why const eqStrict = { equals: strictEqual } isn't exported? It seems it should be.

@gcanti
Copy link
Owner

gcanti commented Oct 8, 2019

Because is meaningful only with primitives.

The following function is not pure with respect to eqStrict

interface Person {
  name: string
}

function makePerson(name: string): Person {
  return { name }
}

@steida
Copy link
Contributor Author

steida commented Oct 8, 2019

Hmm, I am using readonly modifier everywhere, so it's meaningful on an object, but I will have to probably remove it because it sucks with arrays, there is no Mutable type and casting sucks, so then it will be meaningful only with primitives. Ok, thank you for the answer.

@steida steida closed this as completed Oct 8, 2019
@unekinn
Copy link

unekinn commented Nov 12, 2019

It's still useful to have something like this for primitives, though. For instance, I've defined this in my fp-ts utilities:

eq.ts

export type StrictComparable = string | number | boolean;
// Untested, but could probably instead be type Primitive = string | number | bigint | boolean | null | undefined | symbol;

export const eqStrict = <A extends StrictComparable>() => eq.fromEquals<A>(eq.strictEqual);

export const byId = <A, B extends StrictComparable>(f: (a: A) => B) => eq.contramap(f)(eqStrict());

array.ts

export function distinct<A extends StrictComparable>(): (as: A[]) => A[] {
    return flow(array.uniq(eqStrict()));
}

export function distinctBy<A, B extends StrictComparable>(f: (a: A) => B): (as: A[]) => A[] {
    return flow(array.uniq(byId(f)));
}

@gcanti gcanti reopened this Feb 4, 2020
@gcanti gcanti added this to the v2.5 milestone Feb 4, 2020
gcanti added a commit that referenced this issue Feb 4, 2020
gcanti added a commit that referenced this issue Feb 5, 2020
gcanti added a commit that referenced this issue Feb 10, 2020
@gcanti gcanti self-assigned this Feb 11, 2020
gcanti added a commit that referenced this issue Feb 12, 2020
gcanti added a commit that referenced this issue Feb 12, 2020
@gcanti gcanti mentioned this issue Feb 12, 2020
gcanti added a commit that referenced this issue Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment