Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check if an Iterable is empty

License

NotificationsYou must be signed in to change notification settings

sindresorhus/is-empty-iterable

Check if anIterable is empty

More efficient thanArray.from(iterable).length, as it only iterates the first item, which can make a big difference for dynamic iterators, like aGenerator doing an expensive operation.

Install

npm install is-empty-iterable

Usage

importisEmptyIterablefrom'is-empty-iterable';isEmptyIterable([]);//=> trueisEmptyIterable(newSet([1,2]));//=> false

API

isEmptyIterable(iterable)

Returns aboolean.

iterable

Type:Iterable

Note

When using with generators, be aware that generators are consumed after being iterated. This means callingisEmptyIterable() on the same generator instance multiple times will return different results:

function*myGenerator(){yield1;yield2;}constgenerator=myGenerator();isEmptyIterable(generator);//=> falseisEmptyIterable(generator);// Generator is now consumed//=> true

If you need to check the same generator multiple times, create a new generator instance for each check:

function*myGenerator(){yield1;yield2;}isEmptyIterable(myGenerator());//=> falseisEmptyIterable(myGenerator());//=> false

About

Check if an Iterable is empty

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp