Ziggit

Canonical loop structure for reductions (opens in new tab)

One pattern that might be better sometimes is to name the intermediate value differently: var acc: u32 = 0; for (items) |item| acc = @max(acc, item); const max = acc; This leaves a “garbage” variable in scope, but you get the final result as const and not var without extra indentation. If it gets a bit bigger though, I think I will often go for the labeled block instead to not pollute the scope needlessly. Edit: I actually skimmed over the part of your post where you mention this so my commen...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help