#iterators — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #iterators, aggregated by home.social.
-
Generator Functions vs Async Generators: Memory Efficiency Battle
JavaScript generators vs Python async generators. Which language's generator pattern is more powerful for memory-efficient data processing? Mind = blown!
#javascript #python #javascriptvspython #generators #asyncgenerators #memoryefficiency #lazyevaluation #programmingcomparison #codecomparison #javascripttricks #pythontricks #yield #viralcoding #codingshorts #iterators
-
Generator Functions vs Async Generators: Memory Efficiency Battle
JavaScript generators vs Python async generators. Which language's generator pattern is more powerful for memory-efficient data processing? Mind = blown!
#javascript #python #javascriptvspython #generators #asyncgenerators #memoryefficiency #lazyevaluation #programmingcomparison #codecomparison #javascripttricks #pythontricks #yield #viralcoding #codingshorts #iterators
-
Generator Functions vs Async Generators: Memory Efficiency Battle
JavaScript generators vs Python async generators. Which language's generator pattern is more powerful for memory-efficient data processing? Mind = blown!
#javascript #python #javascriptvspython #generators #asyncgenerators #memoryefficiency #lazyevaluation #programmingcomparison #codecomparison #javascripttricks #pythontricks #yield #viralcoding #codingshorts #iterators
-
Generator Functions vs Async Generators: Memory Efficiency Battle
JavaScript generators vs Python async generators. Which language's generator pattern is more powerful for memory-efficient data processing? Mind = blown!
#javascript #python #javascriptvspython #generators #asyncgenerators #memoryefficiency #lazyevaluation #programmingcomparison #codecomparison #javascripttricks #pythontricks #yield #viralcoding #codingshorts #iterators
-
Generator Functions vs Async Generators: Memory Efficiency Battle
JavaScript generators vs Python async generators. Which language's generator pattern is more powerful for memory-efficient data processing? Mind = blown!
#javascript #python #javascriptvspython #generators #asyncgenerators #memoryefficiency #lazyevaluation #programmingcomparison #codecomparison #javascripttricks #pythontricks #yield #viralcoding #codingshorts #iterators
-
Symbol.iterator Creates INFINITE Sequence?!
Custom iterators can generate INFINITE sequences! This object never ends, but spread operator can slice it. This is how generators break the rules of finite data!
#javascript #javascripttricks #symbol.iterator #generators #infinitesequences #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #iterators #advancedjavascript
-
Reverse Iterations
Sometimes, we all need a way to iterate over a container in the opposite direction. There are several ways to reverse-iterate a container, and in this article, we’ll explore them.
Index Iteration
Probably the simplest way, taken from C is to iterate using an index location:
for (int64_t index = ssize(container) - 1; index >= 0; --index) { // do something with `container[index]`}This way is highly not recommended as it might lead to infinite loops if done incorrectly (for example by using
uint64_torsize_tfor the index type), and you can find more issues with this way in some previous articles about iterators in this blog.Reverse Iterators
Another way to iterate a container is by using reverse iterators (
rbegin()andrend()):for (auto it = container.rbegin(); it != container.rend(); ++it) { // do something with `*it`}This is a more recommended way, but it might be a little bit frustrating compared to a regular for-range loop:
for (auto elem : container) { /*do something with `elem`*/ }The closest way to this method using the standard (before C++20) is:
std::for_each(container.rbegin(), container.rend(), [](auto elem) { // so something with `elem`});Ranges (C++20)
If you are using the ranges library, or using at least C++20, you can use the following method to iterate a container in reverse order:
for (auto elem : container | std::views::reverse) { // do something with `elem`}Custom Reverse Container View
Another way to use the for-range loop (even if you don’t use C++20 or the ranges library), is to create your own container mask, to modify the behavior of the
begin()andend()functions:template <typename T>class reverse_view {public: reverse_view(T& cont) : container(&cont) {} typename T::reverse_iterator begin() { return container->rbegin(); } typename T::reverse_iterator end() { return container->rend(); } private: T* container;};Then, you’ll be able to use it like that:
std::vector<int> container = {1, 2, 3, 4, 5};for (int elem : reverse_view(container)) { std::cout << elem << ", ";}More Ways
I hope you learned something new, and feel free to share in the comments if you know other ways to reverse-iterate over a container.
#advanced #C_ #c11 #c14 #c17 #c20 #containers #Intermediate #Iterators #ranges #reverse #reverseIterators
-
Итерация по UENUM в Unreal Engine
Понадобилось мне создать панель категорий размещаемых предметов в UI. В наследие мне достался уже готовый UENUM, который в будущем будет изменен. Естественно, очень не хотелось вручную перемещать и настраивать каждый отдельный виджет. Так еще и заниматься этим в будущем с изменениями категорий. Хотелось чего-то простого и универсального. Чтобы вот вызвал условный For Each Loop и сгенерировал все как надо, еще и не обязательно только для этого енама. Выход был найден! Если мы создаем UENUM, то unreal сам генерит всю нужную инфу и создает для нас UEnum класс, который является UObject. Нужно лишь правильно использовать эту информацию.
https://habr.com/ru/articles/861944/
#uenum #unreal_engine #c++ #blueprints #iterator #iterators #tutorial #async #asynchronous #for_each
-
A couple of nice posts by Claude Heiland-Allen:
“Deep Zoom Theory And Practice” [2021] (https://mathr.co.uk/blog/2021-05-14_deep_zoom_theory_and_practice.html).
“Deep Zoom Theory And Practice (Again)” [2022] (https://mathr.co.uk/blog/2022-02-21_deep_zoom_theory_and_practice_again.html).
-
I’ve been fascinated by the #MandelbrotSet and #Fractals since my college days 😍:
“The Quest To Decode The Mandelbrot Set, Math’s Famed Fractal”, Quanta (https://www.quantamagazine.org/the-quest-to-decode-the-mandelbrot-set-maths-famed-fractal-20240126/).