Comment

Comment by edwardjxli

In that example I gave, I totally agree with you. One area where I find walrus operators kinda useful is with dealing with iterators. For example,

'''

iterable = iter(thing)

while val := next(iterable, None): print(val)

'''

is a lot cleaner in my opinion compared to

'''

iterable = iter(thing)

val = next(iterable, None) while val is not None: print(val) val = next(iterable, None)

'''

Reason why I did not use this example outright was because I wasn't sure if people were familiar with the iter api, so I just chose a simpler example for the blog.

parent edwardjxli 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton