/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/src/private/webapis/utils/ArrayLikeUtils.js
46 строк
1 KB
Tim Yung
RN: Sort Pragmas in Headers (#51554)
23 май 2025, 07:18
23 май 2025, 07:18
1977dd6
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict * @format */ /** * This definition is different from the current built-in type `$ArrayLike` * provided by Flow, in that this is an interface and that one is an object. * * The difference is important because, when using objects, Flow thinks * a `length` property would be copied over when using the spread operator, * which is incorrect. */ export interface ArrayLike<T> extends Iterable<T> { // This property should've been read-only as well, but Flow doesn't handle // read-only indexers correctly (thinks reads are writes and fails). [indexer: number]: T; +length: number; } export function* createValueIterator<T>(arrayLike: ArrayLike<T>): Iterator<T> { for (let i = 0; i < arrayLike.length; i++) { yield arrayLike[i]; } } export function* createKeyIterator<T>( arrayLike: ArrayLike<T>, ): Iterator<number> { for (let i = 0; i < arrayLike.length; i++) { yield i; } } export function* createEntriesIterator<T>( arrayLike: ArrayLike<T>, ): Iterator<[number, T]> { for (let i = 0; i < arrayLike.length; i++) { yield [i, arrayLike[i]]; } }