Re: Cannot instantiate ReturnType with lambda

2025-07-26 Thread monkyyy via Digitalmars-d-learn
On Saturday, 26 July 2025 at 23:08:35 UTC, luafyn wrote: alias U = ReturnType!fn; `ReturnType!(fn!T)` works id avoid being this explicit with types tho, type inference is unidirectional in d, its best to lean into it and follow the natural flow

Re: Examples from "Programming in D" book

2025-07-26 Thread Andy Valencia via Digitalmars-d-learn
On Saturday, 26 July 2025 at 20:35:14 UTC, Brother Bill wrote: I think that if someone is starting with "Programming in D", that sample code that is exhaustive would be helpful. It'll be great to see what you come up with. Thanks for taking such a hands-on approach! Andy

Cannot instantiate ReturnType with lambda

2025-07-26 Thread luafyn via Digitalmars-d-learn
Why doesn't this work? ```d import std; struct Optional(T) { T value; bool hasValue; } auto map(alias fn, T)(Optional!T m) { alias U = ReturnType!fn; if (m.hasValue) { return Optional!U(fn(m.value), true); } else { return Optional!U(); } } void main() {

Re: Examples from "Programming in D" book

2025-07-26 Thread thinkunix via Digitalmars-d-learn
Brother Bill via Digitalmars-d-learn wrote: I think that if someone is starting with "Programming in D", that sample code that is exhaustive would be helpful. I am one of those where code snippets are not an effective way to learn. I need real working code that I can "play" with. Turning a c

Re: Examples from "Programming in D" book

2025-07-26 Thread Brother Bill via Digitalmars-d-learn
On Saturday, 26 July 2025 at 17:48:43 UTC, Monkyyy wrote: On Friday, 25 July 2025 at 21:27:55 UTC, Brother Bill wrote: On Friday, 25 July 2025 at 18:47:19 UTC, Ali Çehreli wrote: On 7/25/25 4:10 AM, Brother Bill wrote: > On Friday, 25 July 2025 at 10:56:08 UTC, novicetoo wrote: >> check https:/

Re: Examples from "Programming in D" book

2025-07-26 Thread Monkyyy via Digitalmars-d-learn
On Friday, 25 July 2025 at 21:27:55 UTC, Brother Bill wrote: On Friday, 25 July 2025 at 18:47:19 UTC, Ali Çehreli wrote: On 7/25/25 4:10 AM, Brother Bill wrote: > On Friday, 25 July 2025 at 10:56:08 UTC, novicetoo wrote: >> check https://ddili.org/ders/d.en/index.html >> under "Code samples as a