11import { MaskSelector , SliceSelector } from "./selectors" ;
2- import { normalizeIndex } from "./utils" ;
2+ import { isCountable , normalizeIndex } from "./utils" ;
33import { KeyError , LengthError , ReadonlyError } from "./excpetions" ;
44import { NormalizedSlice , Slice } from "./structs" ;
55import type { ArrayViewInterface , ArraySelectorInterface , SliceableArray } from "./types" ;
@@ -57,7 +57,7 @@ export class ArrayView<T> implements ArrayViewInterface<T> {
5757 /**
5858 * Constructs a new ArrayView instance based on the provided source array or ArrayView.
5959 *
60- * @param {Array<T> | ArrayView <T> } source - The source array or ArrayView to create a view from.
60+ * @param {Array<T> | ArrayViewInterface <T> } source - The source array or ArrayView to create a view from.
6161 * @param {object } options - Options for configuring the view.
6262 * @param {boolean } [options.readonly=false] - Optional flag to indicate whether the view should be readonly.
6363 *
@@ -70,7 +70,7 @@ export class ArrayView<T> implements ArrayViewInterface<T> {
7070 const loc = Array . isArray ( source ) ? source : source . loc ;
7171 this . source = Array . isArray ( source ) ? source : source . source ;
7272 this . parentView = Array . isArray ( source ) ? undefined : source ;
73- this . readonly = readonly ?? ( ( source instanceof ArrayView ) ? ( source as ArrayView < T > ) . readonly : false ) ;
73+ this . readonly = readonly ?? ( Array . isArray ( source ) ? false : ( source as ArrayViewInterface < T > ) . readonly ) ;
7474
7575 if ( ( source instanceof ArrayView ) && source . readonly && ! this . readonly ) {
7676 throw new ReadonlyError ( "Cannot create non-readonly view for readonly source." ) ;
@@ -156,7 +156,10 @@ export class ArrayView<T> implements ArrayViewInterface<T> {
156156 }
157157
158158 /** @inheritDoc */
159- public applyWith < U > ( data : Array < U > | ArrayView < U > , mapper : ( lhs : T , rhs : U , index : number ) => T ) : ArrayView < T > {
159+ public applyWith < U > (
160+ data : Array < U > | ArrayViewInterface < U > ,
161+ mapper : ( lhs : T , rhs : U , index : number ) => T ,
162+ ) : ArrayView < T > {
160163 if ( data . length !== this . length ) {
161164 throw new LengthError ( `Length of values array not equal to view length (${ data . length } != ${ this . length } ).` ) ;
162165 }
@@ -171,7 +174,16 @@ export class ArrayView<T> implements ArrayViewInterface<T> {
171174 }
172175
173176 /** @inheritDoc */
174- public set ( newValues : Array < T > | ArrayView < T > ) : ArrayView < T > {
177+ public set ( newValue : Array < T > | ArrayViewInterface < T > | T ) : ArrayView < T > {
178+ if ( ! isCountable ( newValue ) ) {
179+ for ( let i = 0 ; i < this . length ; ++ i ) {
180+ this . loc [ i ] = newValue as T ;
181+ }
182+ return this ;
183+ }
184+
185+ const newValues = newValue as Array < T > | ArrayViewInterface < T > ;
186+
175187 if ( newValues . length !== this . length ) {
176188 throw new LengthError ( `Length of values array not equal to view length (${ newValues . length } != ${ this . length } ).` ) ;
177189 }
@@ -236,15 +248,15 @@ export class ArrayIndexListView<T> extends ArrayView<T> {
236248 /**
237249 * Constructs a new ArrayIndexListView instance with the specified source array or ArrayView and indexes array.
238250 *
239- * @param {Array<T> | ArrayView <T> } source - The source array or ArrayView to create a view from.
251+ * @param {Array<T> | ArrayViewInterface <T> } source - The source array or ArrayView to create a view from.
240252 * @param {object } options - Options for configuring the view.
241253 * @param {number[] } options.indexes - The indexes array specifying the indexes of elements in the source array.
242254 * @param {boolean } [options.readonly] - Optional flag to indicate whether the view should be readonly.
243255 *
244256 * @constructor
245257 */
246258 constructor (
247- source : Array < T > | ArrayView < T > ,
259+ source : Array < T > | ArrayViewInterface < T > ,
248260 {
249261 indexes,
250262 readonly,
@@ -297,15 +309,15 @@ export class ArrayMaskView<T> extends ArrayIndexListView<T> {
297309 /**
298310 * Constructs a new ArrayMaskView instance with the specified source array or ArrayView and boolean mask.
299311 *
300- * @param {Array<T> | ArrayView <T> } source - The source array or ArrayView to create a view from.
312+ * @param {Array<T> | ArrayViewInterface <T> } source - The source array or ArrayView to create a view from.
301313 * @param {object } options - Options for configuring the view.
302314 * @param {boolean[] } options.mask - The boolean mask for including or excluding elements from the source array.
303315 * @param {boolean } [options.readonly] - Optional flag to indicate whether the view should be readonly.
304316 *
305317 * @constructor
306318 */
307319 constructor (
308- source : Array < T > | ArrayView < T > ,
320+ source : Array < T > | ArrayViewInterface < T > ,
309321 {
310322 mask,
311323 readonly,
@@ -343,15 +355,15 @@ export class ArraySliceView<T> extends ArrayView<T> {
343355 /**
344356 * Constructs a new ArraySliceView instance with the specified source array or ArrayView and slice range.
345357 *
346- * @param {Array<T> | ArrayView <T> } source - The source array or ArrayView to create a view from.
358+ * @param {Array<T> | ArrayViewInterface <T> } source - The source array or ArrayView to create a view from.
347359 * @param {object } options - Options for configuring the view.
348360 * @param {Slice } options.slice - The slice range specifying the subset of elements to include in the view.
349361 * @param {boolean } [options.readonly] - Optional flag to indicate whether the view should be readonly.
350362 *
351363 * @constructor
352364 */
353365 constructor (
354- source : Array < T > | ArrayView < T > ,
366+ source : Array < T > | ArrayViewInterface < T > ,
355367 {
356368 slice,
357369 readonly,
0 commit comments