this post was submitted on 09 May 2024
446 points (92.2% liked)

Programmer Humor

32589 readers
938 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] AVincentInSpace@pawb.social 4 points 6 months ago (1 children)

what if I need to nest if lets

[–] RustyNova@lemmy.world 4 points 6 months ago (1 children)

Use a match? Unless it's for guard clauses, a match is fine enough

[–] AVincentInSpace@pawb.social 1 points 6 months ago (1 children)

what if i need to if let on the result of another if let

[–] RustyNova@lemmy.world 1 points 6 months ago (1 children)

Oh, then you use and_then() or something similar.

There's also the possibility to use the guard clauses patern and do let <...> = <...> else {}.

And finally, you can always split into another function.

It's not straight rules. It depends on what makes it more readable for your case.

[–] AVincentInSpace@pawb.social 1 points 6 months ago

what about if on a boolean followed by an if let