seq.reduce(into:_:)
Last updated
Last updated
ไฝฟ็จๆญคๆนๆณๆ๏ผไธๅฎ่ฆๅจ updateAccumulatingResult ้ๅ closure ็ function body ่ฃก้ขๆดๆฐ partialResult ้ๅ inout ๅๆธ๏ผreduce(into:_:) ๅฐฑๆฏ้้ๆดๆฐๆญคๅๆธ๏ผๆๅพๅๅฐๆญคๅๆธ็็ดฏ็ฉๆดๆฐ็ธฝ็ตๆ (accumulating result) ็ถๆ return value ๅณๅใ้ไนๆฏ็บไป้บผ้ๅ closure ็จฑ็บ updateAccumulatingResult ไบ๏ผๅ ็บไฝ ๅฟ ้ ๅจๅฎ็ body ่ฃก้ข "update" accumulating result (partialResult)ใ๐ ๆฏ่ผ๏ผseq.reduce(_:_:)
่จป๏ผๆ่ช็บ Apple ๅจ้ๅๆนๆณ็ๅๆธๅ็จฑไธ๏ผๆใๅฝๅไธไธ่ดใ็ๅ้กใๆข็ถ closure ็จฑ็บ updateAccumulatingResult๏ผ้ฃ้บผ partialResult ้ๅ inout ๅๆธๅฐฑๆ่ฉฒๅฝๅ็บ accumulatingResult ๆๆฏ่ผไธ่ดใ
This method is preferred over reduce(_:_:)
for efficiency when the result is a copy-on-write type, for example an Array or a Dictionary.
๐ .reduce(into:_:)
๐ stackoverflow