<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>It’s a shame that Range can’t be made to conform to SetAlgebra as it lacks the required initializers. Is there anything that can be done about this? Actually, it makes me wonder whether those initializers should even be a part of SetAlgebra — why must something implementing SetAlgebra be able to be initialized as empty or from a finite sequence?</div><div><br>On Aug 8, 2017, at 11:23 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">For consistency, the name for this function would be `isSuperset(of:)`, and it would be equally interesting to have `isStrictSuperset(of:)`, `isSubset(of:)`, `isStrictSubset(of:)` and `isDisjoint(with:)`--all currently available for types that conform to `SetAlgebra`.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 9:40 PM, Yuta Koshizawa via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<br><br>Recently I needed to implement `contains` methods to check if a range contains another range. I think those are basic operations and suitable for the standard library.<br><br>Although it may seem easy to implement such `contains` methods whenever we need them, their precise specifications are too complicated to do so.<br><br>e.g.<br><br>let a: ClosedRange<Int> = 2...7<br>a.contains(3...5) // `true`<br>a.contains(3...7) // also `true`<br>a.contains(3..<8) // still `true` because all values contained in `3..<8` are also in `a`<br>a.contains(3..<9) // `false`<br><br>let b: ClosedRange<Float> = 2...7<br>b.contains(3...5) // `true`<br>b.contains(3...7) // `true`<br>b.contains(3..<8) // `false` because { x | 7.0 < x < 8.0 } is not contained in `a`<br><br>let c: Range<Float> = 2..<7<br>c.contains(3...5) // `true`<br>c.contains(3..<7) // `true`<br>c.contains(3...7) // `false` because 7.0 is not contained in `a`<br><br>My experimental implementation is here:<br><a href="https://github.com/koher/range-contains" target="_blank">https://github.com/koher/<wbr>range-contains</a><br>(Currently does not support one-sided ranges)<br><br>What are your thoughts about them?<br><br>--<br>Yuta<br></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>