Title: Feature: Go-like (val, ok) handler deduction for select
Motivation
Currently, consuming data inside a select handler requires manually checking channel state and popping:
select(ch, {
if (!ch.ready) { /* closed */ }
else {
auto val = ch.front;
ch.popFront;
}
});
This is verbose and error-prone. It would be great to mimic Go's val, ok := <-ch mental model, which is widely understood and very LLM-friendly.
Proposal
Utilize D's compile-time reflection to deduce the handler's signature.
1. (val, ok) style (Safe and explicit):
select(ch, (int val, bool ok) {
if (ok) {
// Process val
} else {
// Channel closed and drained
}
});
2. val only style (Convenient, val is T.init if closed):
select(ch, (int val) {
// Process val (might be T.init if closed)
});
This significantly improves DX and aligns perfectly with standard concurrency mental models.
Title: Feature: Go-like
(val, ok)handler deduction forselectMotivation
Currently, consuming data inside a
selecthandler requires manually checking channel state and popping:select(ch, { if (!ch.ready) { /* closed */ } else { auto val = ch.front; ch.popFront; } });This is verbose and error-prone. It would be great to mimic Go's
val, ok := <-chmental model, which is widely understood and very LLM-friendly.Proposal
Utilize D's compile-time reflection to deduce the handler's signature.
1.
(val, ok)style (Safe and explicit):2.
valonly style (Convenient,valisT.initif closed):This significantly improves DX and aligns perfectly with standard concurrency mental models.