<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 10, 2017, at 11:13 PM, Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On May 10, 2017, at 4:51 PM, Ben Cohen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><h1 class="" style="font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255); margin-top: 0px !important;"><p class="" style="box-sizing: border-box; margin: 0px 0px 16px; font-size: 16px; font-weight: normal;">Add a <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">unicodeScalars</code> property to <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Character</code>, presending a lazy view of the scalars in the character, along similar lines to the one on <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">String</code>.</p></h1></div></blockquote></div><div class="">Might it make sense conform `Character` itself to `Collection`, rather than using a view?</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Hmm. I don’t think this would be right. The composition of Character is not fundamental to its very being (unlike String’s composition, where being of element type Character is an important principle for Swift) – it’s a lower-level thing that a user can poke at for specific purposes. </div><div><br class=""></div><div>Also, one of the discoveries we’ve made while making String a Collection is it has some unfortunate effects on code that uses flatMap inapporpriately. You can use flatMap with a function (Element)->T, and it has the same effect as map because the function is implicitly converted to (Element)->T? and then the elements are unwrapped again by the flatMap. But if you were doing this on String, and then String becomes a Collection, suddenly you get the more appropriate flatMap that flattens nested collections, and you get a [Character] back instead of the expected [String]. We’ve been able to put in compatibility shims to detect this specific case so people can be warned in Swift 3 compatibility mode, but I fear making Character a collection too may itself may introduce even more problems, possibly ones we can’t work around without compiler features. This reason alone might not be enough to rule out making Character a collection in the future, but it probably rules it out for Swift 4.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Otherwise, I'm in favor. (Though it'd be nice to have *some* way to manipulate the `UnicodeScalar`s inside a `Character`, even if `RangeReplaceableCollection`'s interface would make preserving its invariants too difficult. That could wait, though.)</div><div class=""><br class="webkit-block-placeholder"></div><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></div></div></blockquote></div><br class=""></body></html>