diff --git a/lodash/lodash-3.10-tests.ts b/lodash/lodash-3.10-tests.ts index e780cf0880..683821044b 100644 --- a/lodash/lodash-3.10-tests.ts +++ b/lodash/lodash-3.10-tests.ts @@ -5003,13 +5003,6 @@ namespace TestReject { } } -result = _.sample([1, 2, 3, 4]); -result = _.sample([1, 2, 3, 4], 2); -result = <_.LoDashImplicitWrapper>_([1, 2, 3, 4]).sample(); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).sample(2); -result = _([1, 2, 3, 4]).sample().value(); -result = _([1, 2, 3, 4]).sample(2).value(); - // _.select namespace TestSelect { let array: TResult[]; @@ -5108,6 +5101,78 @@ namespace TestSelect { } } +// _.sample +namespace TestSample { + let array: string[]; + let list: _.List; + let dictionary: _.Dictionary; + let numericDictionary: _.NumericDictionary; + + { + let result: string; + + result = _.sample('abc'); + result = _.sample(array); + result = _.sample(list); + result = _.sample(dictionary); + result = _.sample(numericDictionary); + result = _.sample<{a: string}, string>({a: 'foo'}); + result = _.sample({a: 'foo'}); + + result = _('abc').sample(); + result = _(array).sample(); + result = _(list).sample(); + result = _(dictionary).sample(); + result = _(numericDictionary).sample(); + result = _({a: 'foo'}).sample(); + } + + { + let result: string[]; + + result = _.sample('abc', 42); + result = _.sample(array, 42); + result = _.sample(list, 42); + result = _.sample(dictionary, 42); + result = _.sample(numericDictionary, 42); + result = _.sample<{a: string}, string>({a: 'foo'}, 42); + result = _.sample({a: 'foo'}, 42); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _('abc').sample(42); + result = _(array).sample(42); + result = _(list).sample(42); + result = _(dictionary).sample(42); + result = _(numericDictionary).sample(42); + result = _({a: 'foo'}).sample(42); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().sample(); + result = _(array).chain().sample<_.LoDashExplicitWrapper>(); + result = _(list).chain().sample<_.LoDashExplicitWrapper>(); + result = _(dictionary).chain().sample<_.LoDashExplicitWrapper>(); + result = _(numericDictionary).chain().sample<_.LoDashExplicitWrapper>(); + result = _({a: 'foo'}).chain().sample<_.LoDashExplicitWrapper>(); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _('abc').chain().sample(42); + result = _(array).chain().sample(42); + result = _(list).chain().sample(42); + result = _(dictionary).chain().sample(42); + result = _(numericDictionary).chain().sample(42); + result = _({a: 'foo'}).chain().sample(42); + } +} + // _.shuffle namespace TestShuffle { let array: TResult[]; diff --git a/lodash/lodash-3.10.d.ts b/lodash/lodash-3.10.d.ts index 47bc4e0c9a..cb0e0b45c7 100644 --- a/lodash/lodash-3.10.d.ts +++ b/lodash/lodash-3.10.d.ts @@ -8008,56 +8008,6 @@ declare module _ { reject(predicate: W): LoDashExplicitArrayWrapper; } - //_.sample - interface LoDashStatic { - /** - * Retrieves a random element or n random elements from a collection. - * @param collection The collection to sample. - * @return Returns the random sample(s) of collection. - **/ - sample(collection: Array): T; - - /** - * @see _.sample - **/ - sample(collection: List): T; - - /** - * @see _.sample - **/ - sample(collection: Dictionary): T; - - /** - * @see _.sample - * @param n The number of elements to sample. - **/ - sample(collection: Array, n: number): T[]; - - /** - * @see _.sample - * @param n The number of elements to sample. - **/ - sample(collection: List, n: number): T[]; - - /** - * @see _.sample - * @param n The number of elements to sample. - **/ - sample(collection: Dictionary, n: number): T[]; - } - - interface LoDashImplicitArrayWrapper { - /** - * @see _.sample - **/ - sample(n: number): LoDashImplicitArrayWrapper; - - /** - * @see _.sample - **/ - sample(): LoDashImplicitWrapper; - } - //_.select interface LoDashStatic { /** @@ -8217,6 +8167,141 @@ declare module _ { select(predicate: W): LoDashExplicitArrayWrapper; } + //_.sample + interface LoDashStatic { + /** + * Gets a random element or n random elements from a collection. + * + * @param collection The collection to sample. + * @return Returns the random sample(s) of collection. + */ + sample( + collection: List|Dictionary|NumericDictionary, + n: number + ): T[]; + + /** + * @see _.sample + */ + sample( + collection: O, + n: number + ): T[]; + + /** + * @see _.sample + */ + sample( + collection: Object, + n: number + ): T[]; + + /** + * @see _.sample + */ + sample( + collection: List|Dictionary|NumericDictionary + ): T; + + /** + * @see _.sample + */ + sample( + collection: O + ): T; + + /** + * @see _.sample + */ + sample( + collection: Object + ): T; + } + + interface LoDashImplicitWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashImplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): string; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashImplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): T; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashImplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): T; + } + + interface LoDashExplicitWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashExplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashExplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): TWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sample + */ + sample( + n: number + ): LoDashExplicitArrayWrapper; + + /** + * @see _.sample + */ + sample(): TWrapper; + } + //_.shuffle interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8435ff8e9c..19af6c147f 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5042,14 +5042,103 @@ namespace TestReject { } // _.sample -result = _.sample([1, 2, 3, 4]); -result = <_.LoDashImplicitWrapper>_([1, 2, 3, 4]).sample(); -result = _([1, 2, 3, 4]).sample().value(); +namespace TestSample { + let array: string[]; + let list: _.List; + let dictionary: _.Dictionary; + let numericDictionary: _.NumericDictionary; + + { + let result: string; + + result = _.sample('abc'); + result = _.sample(array); + result = _.sample(list); + result = _.sample(dictionary); + result = _.sample(numericDictionary); + result = _.sample<{a: string}, string>({a: 'foo'}); + result = _.sample({a: 'foo'}); + + result = _('abc').sample(); + result = _(array).sample(); + result = _(list).sample(); + result = _(dictionary).sample(); + result = _(numericDictionary).sample(); + result = _({a: 'foo'}).sample(); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().sample(); + result = _(array).chain().sample<_.LoDashExplicitWrapper>(); + result = _(list).chain().sample<_.LoDashExplicitWrapper>(); + result = _(dictionary).chain().sample<_.LoDashExplicitWrapper>(); + result = _(numericDictionary).chain().sample<_.LoDashExplicitWrapper>(); + result = _({a: 'foo'}).chain().sample<_.LoDashExplicitWrapper>(); + } +} // _.sampleSize -result = _.sampleSize([1, 2, 3, 4], 2); -result = <_.LoDashImplicitArrayWrapper>_([1, 2, 3, 4]).sampleSize(2); -result = _([1, 2, 3, 4]).sampleSize(2).value(); +namespace TestSampleSize { + let array: string[]; + let list: _.List; + let dictionary: _.Dictionary; + let numericDictionary: _.NumericDictionary; + + { + let result: string[]; + + result = _.sampleSize('abc'); + result = _.sampleSize('abc', 42); + result = _.sampleSize(array); + result = _.sampleSize(array, 42); + result = _.sampleSize(list); + result = _.sampleSize(list, 42); + result = _.sampleSize(dictionary); + result = _.sampleSize(dictionary, 42); + result = _.sampleSize(numericDictionary); + result = _.sampleSize(numericDictionary, 42); + result = _.sampleSize<{a: string}, string>({a: 'foo'}); + result = _.sampleSize<{a: string}, string>({a: 'foo'}, 42); + result = _.sampleSize({a: 'foo'}); + result = _.sampleSize({a: 'foo'}, 42); + } + + { + let result: _.LoDashImplicitArrayWrapper; + + result = _('abc').sampleSize(); + result = _('abc').sampleSize(42); + result = _(array).sampleSize(); + result = _(array).sampleSize(42); + result = _(list).sampleSize(); + result = _(list).sampleSize(42); + result = _(dictionary).sampleSize(); + result = _(dictionary).sampleSize(42); + result = _(numericDictionary).sampleSize(); + result = _(numericDictionary).sampleSize(42); + result = _({a: 'foo'}).sampleSize(); + result = _({a: 'foo'}).sampleSize(42); + } + + { + let result: _.LoDashExplicitArrayWrapper; + + result = _('abc').chain().sampleSize(); + result = _('abc').chain().sampleSize(42); + result = _(array).chain().sampleSize(); + result = _(array).chain().sampleSize(42); + result = _(list).chain().sampleSize(); + result = _(list).chain().sampleSize(42); + result = _(dictionary).chain().sampleSize(); + result = _(dictionary).chain().sampleSize(42); + result = _(numericDictionary).chain().sampleSize(); + result = _(numericDictionary).chain().sampleSize(42); + result = _({a: 'foo'}).chain().sampleSize(); + result = _({a: 'foo'}).chain().sampleSize(42); + } +} // _.shuffle namespace TestShuffle { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index d0544bc4c9..329c759e8b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8981,77 +8981,155 @@ declare module _ { //_.sample interface LoDashStatic { /** - * Gets a random element from `collection`. + * Gets a random element from collection. * - * @static - * @memberOf _ - * @category Collection - * @param {Array|Object} collection The collection to sample. - * @returns {*} Returns the random element. - * @example - * - * _.sample([1, 2, 3, 4]); - * // => 2 + * @param collection The collection to sample. + * @return Returns the random element. */ - sample(collection: Array): T; + sample( + collection: List|Dictionary|NumericDictionary + ): T; /** - * @see _.sample - **/ - sample(collection: List): T; + * @see _.sample + */ + sample( + collection: O + ): T; /** - * @see _.sample - **/ - sample(collection: Dictionary): T; + * @see _.sample + */ + sample( + collection: Object + ): T; + } + + interface LoDashImplicitWrapper { + /** + * @see _.sample + */ + sample(): string; } interface LoDashImplicitArrayWrapper { /** * @see _.sample - **/ - sample(): LoDashImplicitWrapper; + */ + sample(): T; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.sample + */ + sample(): T; + } + + interface LoDashExplicitWrapper { + /** + * @see _.sample + */ + sample(): LoDashExplicitWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sample + */ + sample(): TWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sample + */ + sample(): TWrapper; } //_.sampleSize interface LoDashStatic { /** - * Gets `n` random elements from `collection`. + * Gets n random elements at unique keys from collection up to the size of collection. * - * @static - * @memberOf _ - * @category Collection - * @param {Array|Object} collection The collection to sample. - * @param {number} [n=0] The number of elements to sample. - * @returns {Array} Returns the random elements. - * @example - * - * _.sampleSize([1, 2, 3, 4], 2); - * // => [3, 1] + * @param collection The collection to sample. + * @param n The number of elements to sample. + * @return Returns the random elements. */ - sampleSize(collection: Array, n: number): T[]; + sampleSize( + collection: List|Dictionary|NumericDictionary, + n?: number + ): T[]; /** - * @see _.sampleSize - **/ - sampleSize(collection: List, n: number): T[]; + * @see _.sampleSize + */ + sampleSize( + collection: O, + n?: number + ): T[]; /** - * @see _.sampleSize - **/ - sampleSize(collection: Dictionary, n: number): T[]; + * @see _.sampleSize + */ + sampleSize( + collection: Object, + n?: number + ): T[]; + } + + interface LoDashImplicitWrapper { + /** + * @see _.sampleSize + */ + sampleSize( + n?: number + ): LoDashImplicitArrayWrapper; } interface LoDashImplicitArrayWrapper { /** * @see _.sampleSize - **/ - sampleSize(n: number): LoDashImplicitArrayWrapper; + */ + sampleSize( + n?: number + ): LoDashImplicitArrayWrapper; + } + interface LoDashImplicitObjectWrapper { /** * @see _.sampleSize - **/ - sampleSize(): LoDashImplicitWrapper; + */ + sampleSize( + n?: number + ): LoDashImplicitArrayWrapper; + } + + interface LoDashExplicitWrapper { + /** + * @see _.sampleSize + */ + sampleSize( + n?: number + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.sampleSize + */ + sampleSize( + n?: number + ): LoDashExplicitArrayWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.sampleSize + */ + sampleSize( + n?: number + ): LoDashExplicitArrayWrapper; } //_.shuffle