[JAVA] Generator memo.

Generator memo.

Generator is iterator?

PHP:

function generator () {
  yield 0;
  yield 1;
  yield 2;
}
foreach (generator() as $n) {
  echo $n."\n";
}
# 0
# 1
# 2

Python:

def generator():
  yield 0
  yield 1
  yield 2

for n in generator():
  print(n)

# 0
# 1
# 2

JavaScript:

function* generator () {
  yield 0
  yield 1
  yield 2
}
generator().forEach(function (n) {
  console.log(n)
})
// TypeError: generator(...).forEach is not a function
//that...?

A JavaScript generator is a coroutine, not an iterator? But in general, it's easier to understand a generator if you start with an understanding from iterator. But you can't touch the generator with the JavaScript iterator method.

Recommended Posts

Generator memo.
generator
Generator
gzip memo
Raspberry-pi memo
Python memo
graphene memo
Flask memo
pyenv memo
Matplotlib memo
sed memo
Python memo
Install Memo
BeautifulSoup4 memo
networkx memo
python memo
tomcat memo
command memo
psycopg2 memo
Python memo
SSH memo
Command memo
Memo: rtl8812
pandas memo
Shell memo
Python memo
Pycharm memo
Python memo
AtCoder devotion memo (11/12)
[OpenCV] Personal memo
[Python] Memo dictionary
PyPI push memo
tensorflow-gpu introduction memo
LPIC304 virtualization memo
Natural number generator
ALDA execution memo
python beginner memo (9.2-10)
Hash password generator
Password generator creation notes
generator
Generator
Generator memo.
Try numpy.random Generator
youtube download memo
Linux x memo
Django Learning Memo
ARC # 016 Participation memo
Hash password generator
Beautiful Soup memo
python beginner memo (9.1)
linux (ubuntu) memo
scp command memo
Flask Primer Memo
[Python] Generator function
who command memo
django tutorial memo
Flask basic memo
Linux # Command Memo 1
★ Memo ★ Python Iroha
Gender recognition memo
Image reading memo
[MEMO] [TERMINAL] Alacritty
3D rotation memo (1)
[Python] EDA memo
Python 3 operator memo