seq.reduce(_:_:)
Last updated
Was this helpful?
Last updated
Was this helpful?
โฉ โฉ
on every execution of the combine function, a brand-new array is being created by appending the transformed or included element to the previous one. This means that both these implementations are O(nยฒ), not O(n) ...
๐ Advanced Swift, p.37
ๅช่ฆ่จญๅฎไธๅๅๅงๅผ (initialResult)๏ผๆญคๆนๆณๅฐฑๆไฝฟ็จ nextPartialResult ้ๅ closure ไพ้ฒ่ก็ดฏ็ฎ๏ผไธฆๅฐๆๅพ็็ดฏ็ฎ็ตๆๅๅณใ ๆฏ่ผ๏ผseq.reduce(into:_:)
is preferred over for efficiency when the result is a copy-on-write type, for example an Array or a Dictionary.
๐