Re: Sum string lengths

2020-05-14 Thread Andrey via Digitalmars-d-learn
Thanks everyone.

Re: Sum string lengths

2020-05-13 Thread MoonlightSentinel via Digitalmars-d-learn
On Wednesday, 13 May 2020 at 13:52:13 UTC, Andrey wrote: Hi, I want to sum lengths of all strings in array: auto data = ["qwerty", "az", ""]; Fold and reduce doesn't work: auto result = data.fold!`a + b.length`(0U); gives error: static assert: "Incompatible function/seed/element:

Re: Sum string lengths

2020-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 13, 2020 at 01:52:13PM +, Andrey via Digitalmars-d-learn wrote: > Hi, > I want to sum lengths of all strings in array: > > auto data = ["qwerty", "az", ""]; data.map!(s => s.length).sum; T -- It only takes one twig to burn down a forest.

Sum string lengths

2020-05-13 Thread Andrey via Digitalmars-d-learn
Hi, I want to sum lengths of all strings in array: auto data = ["qwerty", "az", ""]; Fold and reduce doesn't work: auto result = data.fold!`a + b.length`(0U); gives error: static assert: "Incompatible function/seed/element: binaryFun/uint/string" How to do it in one line?