GithubHelp home page GithubHelp logo

Comments (8)

leeoniya avatar leeoniya commented on May 24, 2024 1

probably would be more flexible as a function, and more uniform with the rest of the lib.

.not(e => e == 2)

EDIT: eh, i guess my version is just the inverse of filter. i'd still prefer to keep the minimal api:

.filter(e => e !== 2)

/$0.02

from fromfrom.

jtenner avatar jtenner commented on May 24, 2024

I was just reading the TODO.md and agree with your thoughts. What sort of work can be done instead?

from fromfrom.

jtenner avatar jtenner commented on May 24, 2024

Sidenote: some functions could just be shorthand aliases for things.

export const withoutIterable = <TItem>(
  iterable: Iterable<TItem>,
  items: TItem[],
): Iterable<TItem> => {
  return filterIterable(iterable, e => !items.includes(e));
}

Keeps the implementation minimal.

from fromfrom.

tomi avatar tomi commented on May 24, 2024

Hi and thank you for opening an issue. I'm happy to hear that you are willing to contribute!

What I had in mind with except is pretty much what you described, i.e. what lodash's without also does. But instead of expecting an array, we could accept any Iterable<TItem>. This way we can support other iterable objects besides arrays. So the signature could be:

.except(items: Iterable<TItem>): Sequence<TItem> {...}
// Or .without, I'm okay with using either name

Also it might make sense to have an overloaded method that accepts a custom equality comparer to compare the items, but this can also be added later on. The signature for that would be:

.except(items: Iterable<TItem>, comparer: EqualityCompareFn<TItem>): Sequence<TItem> {...}
// where the type for compare function is:
type EqualityCompareFn<TItem> = (a: TItem, b: TItem) => boolean;

And regarding the implementation, I do like using the filterIterable 👍 The given items could be first converted to Set tho, as Array.prototype.includes is O(n) where as Set.prototype.has is O(log(n)) or O(1) (at least according to this).

from fromfrom.

jtenner avatar jtenner commented on May 24, 2024

Great! I'm sorry for taking a while to get back to this issue. Let me spin up a pull request and I'll make some changes.

Question, because my brain likes lots of clarification. How should I use an EqualityCompareFn?

This is what I would personally expect when I use the without operation.

import { createFilterIterable } from "./filter";

export const createWithoutIterable = <TItem>(
  iterable: Iterable<TItem>,
  items: TItem[],
): Sequence<TItem> => {
  const set = new Set(items);
  return createFilterIterable(iterable, item => !set.has(item));
}

from fromfrom.

tomi avatar tomi commented on May 24, 2024

No worries, there's no rush :)

The idea behind EqualityCompareFn would be to allow the user to provide a custom function that compares if two objects are equal, instead of using the sameValueZero comparison. However, Set does not support providing a custom function for comparing the equality of two items. So I think at this point we can forget that and add it later on if it's actually needed.

from fromfrom.

jtenner avatar jtenner commented on May 24, 2024

#31 addresses this enhancement as far as I am capable of. Thanks for the quick responses.

from fromfrom.

tomi avatar tomi commented on May 24, 2024

Available in 1.2.0 🎉

from fromfrom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.