2222
2323var setReadOnly = require ( '@stdlib/utils/define-nonenumerable-read-only-property' ) ;
2424var isArrayLike = require ( '@stdlib/assert/is-array-like' ) ;
25+ var isTypedArrayLike = require ( '@stdlib/assert/is-typed-array-like' ) ;
2526var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
2627var randu = require ( '@stdlib/random/base/mt19937' ) . factory ;
2728var copy = require ( '@stdlib/utils/copy' ) ;
@@ -43,7 +44,7 @@ var slice = Array.prototype.slice;
4344/**
4445* Returns a function to sample elements from an array-like object.
4546*
46- * @param {ArrayLike } [pool] - array-like object from which to sample
47+ * @param {( ArrayLike|TypedArrayLike) } [pool] - array-like object from which to sample
4748* @param {Options } [options] - function options
4849* @param {PositiveInteger } [options.seed] - integer-valued seed
4950* @param {NonNegativeInteger } [options.size] - sample size
@@ -144,7 +145,7 @@ function factory() {
144145
145146 conf = copy ( defaults ) ;
146147 if ( arguments . length === 1 ) {
147- if ( isArrayLike ( arguments [ 0 ] ) ) {
148+ if ( isArrayLike ( arguments [ 0 ] ) || isTypedArrayLike ( arguments [ 0 ] ) ) { // eslint-disable-line max-len
148149 pool = arguments [ 0 ] ;
149150 } else {
150151 config = arguments [ 0 ] ;
@@ -153,7 +154,7 @@ function factory() {
153154 } else if ( arguments . length > 1 ) {
154155 pool = arguments [ 0 ] ;
155156 config = arguments [ 1 ] ;
156- if ( ! isArrayLike ( pool ) ) {
157+ if ( ! ( isArrayLike ( pool ) || isTypedArrayLike ( pool ) ) ) {
157158 throw new TypeError ( 'invalid argument. `pool` argument must be array-like. Value: `' + pool + '`.' ) ;
158159 }
159160 err = validate ( conf , config ) ;
@@ -189,7 +190,7 @@ function factory() {
189190 * Samples elements from an array-like object.
190191 *
191192 * @private
192- * @param {ArrayLike } x - array-like object from which to sample elements
193+ * @param {( ArrayLike|TypedArrayLike) } x - array-like object from which to sample elements
193194 * @param {Options } [options] - function options
194195 * @param {NonNegativeInteger } [options.size] - sample size
195196 * @param {ProbabilityArray } [options.probs] - element probabilities
@@ -208,7 +209,7 @@ function factory() {
208209 var size ;
209210 var err ;
210211
211- if ( ! isArrayLike ( x ) ) {
212+ if ( ! ( isArrayLike ( x ) || isTypedArrayLike ( x ) ) ) {
212213 throw new TypeError ( 'invalid argument. First argument must be array-like. Value: `' + x + '`.' ) ;
213214 }
214215 if ( isString ( x ) ) {
0 commit comments