-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Feature Request: mean, median, sum #2942
Comments
Thanks for reaching out @penguinsAreFunny! This is the right place for feature requests. Underscore aims to stay mean and lean, so it includes only the most fundamental functions that nearly every application needs. For all other functions, we have Underscore-contrib, an open-ended extension library where people can contribute "ad libitum". It so happens that somebody already made a start at contributing these and a few other statistical functions to contrib over here: documentcloud/underscore-contrib#243. If you want, you can take off where @kpkalwa left it. For historical reference: @AndreasBriese himself made the same proposal in #441. |
@jgonggrijp Sorry to ping you back here again. Beside I am migrating from |
@shtse8 Thank you for reaching out; no need to apologize. Unfortunately, once a function is added to Underscore through Even if treeshaking were possible, though, users who load the monolithic interface from a CDN would not benefit. So that is another reason to keep Underscore lean, which will persist even in an Underscore 2.0 without Fortunately for you, TypeScript has module augmentation. Taking import {
mixin,
UnderscoreStatic,
Underscore,
_Chain,
_ChainSingle,
Collection,
TypeOfCollection
} from 'underscore';
import { sum } from './your/own/code.ts';
// The regular JavaScript part
mixin({sum});
// The keeping TS happy part
declare module 'underscore' {
// Unfortunately, due to the way @types/underscore is currently setup,
// you always need to extend three interfaces. Check the source in the
// DefinitelyTyped project for implementation details and examples.
// Interface #1 - declaring the function in its "standalone" form
interface UnderscoreStatic {
// This part depends a bit on the exact interface of your `sum` function.
sum<V extends Collection<any>>(collection: V): TypeOfCollection<V>;
}
// Interface #2 - declaring the function in OOP form
interface Underscore<T, V = T[]> {
// This part again depends on the exact interface of your function
sum(): T;
}
// Interface #3 - declaring the function in chaining form
interface _Chain<T, V = T[]> {
// Again, depends on your function's exact interface
sum(): _ChainSingle<T>;
}
} Admittedly, this is much more trouble for you than if |
Hello,
I am not sure where to post a feature request as I am not used to Github yet.
Is this the right place for feature requests?
I would like support for simple arithmetic operations like mean, median, sum (and perhaps some more) in underscore.
Like this: https://gist.github.com/AndreasBriese/1670507
Some more suggestions: difference, relativeDifferences, minDifference, maxDifference, minRelativeDifference, maxRelativeDifference, meanDifference, meanRelativeDifference, ...
I would also like to suggest support for functions like numpy-python:
Example:
https://numpy.org/doc/stable/reference/generated/numpy.sum.html
https://numpy.org/doc/stable/reference/routines.html
The text was updated successfully, but these errors were encountered: