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

Intersect #19

Open
isc30 opened this issue Mar 1, 2018 · 5 comments
Open

Intersect #19

isc30 opened this issue Mar 1, 2018 · 5 comments

Comments

@isc30
Copy link
Owner

isc30 commented Mar 1, 2018

Produces the set intersection of two sequences (deferred execution)

Proposed signature:

export interface IQueryable<TOut>
{
    intersect(other: IQueryable<TOut>): IEnumerable<TOut>;
}
@isc30 isc30 created this issue from a note in v1.0 - First basic version (To Do) Mar 1, 2018
@nikolalukovic
Copy link
Contributor

nikolalukovic commented Mar 2, 2018

I suppose we will also need to have something like an EqualityComparer to specify in which way to compare values?

We would have an optional value which would specify in which way to do an intersection. Something like this?

export interface IQueryable<TOut>
{
    intersect(other: IQueryable<TOut>, comparer?: EqualityComparer<TOut>): IEnumerable<TOut>;
}

Maybe it would also be a good idea to create comparers for simple types(string, number, etc...) which would be automatically used(depending on the type) if no comparer is specified.

@isc30
Copy link
Owner Author

isc30 commented Mar 2, 2018

The only place where comparers are being used currently is for orderBy, maybe it's a good idea to introduce a StrictEqualityComparer that simply does === and start using it here as default one?

We can introduce something like this:

export type EqualityComparer<T> = (left: T, right: T) => boolean;
export const StrictEqualityComparer = <T>() => (left: T, right: T) => left === right;

@nikolalukovic
Copy link
Contributor

It all depends how precise you want to go. I'd argue that for strings, as an example, being careful about locale is a must. And === doesn't help in that case.

@isc30
Copy link
Owner Author

isc30 commented Mar 2, 2018

yep, but in the end, having special comparer for those cases is user's responsibility.
I think the best we can do is use === as default (every other method in the library uses this comparer)
I also edited my previous answer

@isc30 isc30 self-assigned this Apr 26, 2018
@Tholdrim
Copy link
Contributor

Since EqualityComparer is there already, I'll grab this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants