Comments (8)
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.
I was just reading the TODO.md
and agree with your thoughts. What sort of work can be done instead?
from fromfrom.
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.
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 array
s. 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
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.
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.
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.
#31 addresses this enhancement as far as I am capable of. Thanks for the quick responses.
from fromfrom.
Available in 1.2.0
from fromfrom.
Related Issues (20)
- how about a simple range generator? HOT 1
- The automated release is failing 🚨
- An in-range update of replace-in-file is breaking the build 🚨 HOT 1
- An in-range update of copy-webpack-plugin is breaking the build 🚨 HOT 5
- The automated release is failing 🚨
- [Question]: Are they plans to use a more FP approach? HOT 1
- Performance HOT 2
- why not write transducers? HOT 4
- Chosen TSlib is es2015 HOT 4
- [Questions] Working with deep nested data and arrays of parameters HOT 2
- An in-range update of ts-jest is breaking the build 🚨 HOT 3
- An in-range update of webpack-dev-server is breaking the build 🚨 HOT 10
- Aggregate operations with (and without) groupBy HOT 1
- Doc: Add usage example for sequence methods HOT 1
- Can I use an object as a keyselector in a groupBy HOT 4
- An in-range update of file-loader is breaking the build 🚨 HOT 1
- An in-range update of semantic-release is breaking the build 🚨 HOT 7
- Sequence created from object is not iterable more than once
- Small bug in the type of toObject when a key selector is specified HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fromfrom.