mapValuesWithKeys
-
[SE-0510] Introduce Dictionary.mapValuesWithKeysSwift 2026. 2. 21. 00:45
์๋ ํ์ธ์. ๊ทธ๋ฆฐ์ ๋๋ค ๐์ด๋ฒ ํฌ์คํ ์์๋ SE-0510 Introduce Dictionary.mapValuesWithKeys์ ๋ํด ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ค ๐๐ปIntroDictionary์ ๊ฐ์ ๋ณํํ ๋ key ์ ๋ณด๋ ํจ๊ป ํ์ํ ๊ฒฝ์ฐ๊ฐ ์ข ์ข ์์ต๋๋ค.ํ์ง๋ง ํ์ฌ๋ ์ด๋ฐ ์์ ์ ํ๋ ค๋ฉด init(uniqueKeysWithValues:)๋ reduce(into:)๋ฅผ ์จ์ผ ํ๋๋ฐ, ์ด๋ค์ ๋ถํ์ํ๊ฒ dictionary๋ฅผ rehashingํ๊ฑฐ๋ ์ฌํ ๋นํ๋ ๋น์ฉ์ด ๋ฐ์ํฉ๋๋ค. SE-0510์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด mapValuesWithKeys๋ผ๋ ์๋ก์ด ๋ฉ์๋๋ฅผ ์ ์ํฉ๋๋ค.Key ์ ๋ณด๋ฅผ transformation closure์ ์ ๋ฌํ๋ฉด์๋ ์ฑ๋ฅ ์ค๋ฒํค๋ ์์ด ๊ฐ๋ง ๋ณํํ ์ ์์ต๋๋ค ๐ ํ์ฌ ์์ ์์๋..