diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 3ad298278..77cfd0a63 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -624,6 +624,34 @@ result = _(stoogesAgesDict).sum('age'); result = _.pluck(stoogesAges, 'name'); result = _(stoogesAges).pluck('name').value(); +// _.partition +result = _.partition('abcd', (n) => n < 'c'); +result = _.partition(['a', 'b', 'c', 'd'], (n) => n < 'c'); +result = _.partition([1, 2, 3, 4], (n) => n < 3); +result = _.partition({0: 1, 1: 2, 2: 3, 3: 4, length: 4}, (n) => n < 3); +result = _.partition({a: 1, b: 2, c: 3, d: 4}, (n) => n < 3); +result = <{a: number}[][]>_.partition<{a: number}, {a: number}>([{a: 1}, {a: 2}], {a: 2}); +result = <{a: number}[][]>_.partition<{a: number}, {a: number}>({0: {a: 1}, 1: {a: 2}, length: 2}, {a: 2}); +result = <{a: number}[][]>_.partition<{a: number}, {a: number}>({0: {a: 1}, 1: {a: 2}}, {a: 2}); +result = <{a: number}[][]>_.partition<{a: number}>([{a: 1}, {a: 2}], 'a'); +result = <{a: number}[][]>_.partition<{a: number}>([{a: 1}, {a: 2}], 'a', 2); +result = <{a: number}[][]>_.partition<{a: number}>({0: {a: 1}, 1: {a: 2}, length: 2}, 'a'); +result = <{a: number}[][]>_.partition<{a: number}>({0: {a: 1}, 1: {a: 2}, length: 2}, 'a', 2); +result = <{a: number}[][]>_.partition<{a: number}>({0: {a: 1}, 1: {a: 2}}, 'a'); +result = <{a: number}[][]>_.partition<{a: number}>({0: {a: 1}, 1: {a: 2}}, 'a', 2); +result = _('abcd').partition((n) => n < 'c').value(); +result = _(['a', 'b', 'c', 'd']).partition((n) => n < 'c').value(); +result = _([1, 2, 3, 4]).partition((n) => n < 3).value(); +result = _({0: 1, 1: 2, 2: 3, 3: 4, length: 4}).partition((n) => n < 3).value(); +result = _({a: 1, b: 2, c: 3, d: 4}).partition((n) => n < 3).value(); +result = <{a: number}[][]>_([{a: 1}, {a: 2}]).partition<{a: number}>({a: 2}).value(); +result = <{a: number}[][]>_({0: {a: 1}, 1: {a: 2}, length: 2}).partition<{a: number}, {a: number}>({a: 2}).value(); +result = <{a: number}[][]>_({0: {a: 1}, 1: {a: 2}}).partition<{a: number}, {a: number}>({a: 2}).value(); +result = <{a: number}[][]>_([{a: 1}, {a: 2}]).partition('a').value(); +result = <{a: number}[][]>_([{a: 1}, {a: 2}]).partition('a', 2).value(); +result = <{a: number}[][]>_({0: {a: 1}, 1: {a: 2}}).partition<{a: number}>('a').value(); +result = <{a: number}[][]>_({0: {a: 1}, 1: {a: 2}}).partition<{a: number}>('a', 2).value(); + interface ABC { [index: string]: number; a: number; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 074bced1a..d7282a2a1 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -4081,6 +4081,154 @@ declare module _ { property: string): LoDashArrayWrapper; } + //_.partition + interface LoDashStatic { + /** + * Creates an array of elements split into two groups, the first of which contains elements predicate returns truthy for, + * while the second of which contains elements predicate returns falsey for. + * The predicate is bound to thisArg and invoked with three arguments: (value, index|key, collection). + * + * If a property name is provided for predicate the created _.property style callback + * returns the property value of the given element. + * + * If a value is also provided for thisArg the created _.matchesProperty style callback + * returns true for elements that have a matching property value, else false. + * + * If an object is provided for predicate the created _.matches style callback returns + * true for elements that have the properties of the given object, else false. + * + * @param collection The collection to iterate over. + * @param callback The function called per iteration. + * @param thisArg The this binding of predicate. + * @return Returns the array of grouped elements. + **/ + partition( + collection: List, + callback: ListIterator, + thisArg?: any): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: Dictionary, + callback: DictionaryIterator, + thisArg?: any): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: List, + whereValue: W): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: Dictionary, + whereValue: W): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: List, + path: string, + srcValue: any): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: Dictionary, + path: string, + srcValue: any): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: List, + pluckValue: string): T[][]; + + /** + * @see _.partition + **/ + partition( + collection: Dictionary, + pluckValue: string): T[][]; + } + + interface LoDashStringWrapper { + /** + * @see _.partition + */ + partition( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + } + + interface LoDashArrayWrapper { + /** + * @see _.partition + */ + partition( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + /** + * @see _.partition + */ + partition( + whereValue: W): LoDashArrayWrapper; + /** + * @see _.partition + */ + partition( + path: string, + srcValue: any): LoDashArrayWrapper; + /** + * @see _.partition + */ + partition( + pluckValue: string): LoDashArrayWrapper; + } + + interface LoDashObjectWrapper { + /** + * @see _.partition + */ + partition( + callback: ListIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.partition + */ + partition( + callback: DictionaryIterator, + thisArg?: any): LoDashArrayWrapper; + + /** + * @see _.partition + */ + partition( + whereValue: W): LoDashArrayWrapper; + + /** + * @see _.partition + */ + partition( + path: string, + srcValue: any): LoDashArrayWrapper; + + /** + * @see _.partition + */ + partition( + pluckValue: string): LoDashArrayWrapper; + } + //_.reduce interface LoDashStatic { /**