[swift-evolution] [Review] SE-0065 A New Model for Collections and Indices

Dmitri Gribenko gribozavr at gmail.com
Mon Apr 11 11:22:54 CDT 2016


On Mon, Apr 11, 2016 at 9:20 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> Hi,
>
> On Mon, Apr 11, 2016 at 9:16 AM, Gwendal Roué <swift-evolution at swift.org> wrote:
>> Will it still be possible with the new protocol and types? Especially, how to I generate "BETWEEN 0 AND 17" from 0..<18 without a supporting collection that gives me the predecessor of 18?
>
> You would either design your API to accept a CountableRange, or a
> Range where Bound conforms to Strideable.

You could also make your API generic over RangeProtocol where Bound
conforms to Strideable, check if the end point is contained in the
range (detecting closed ranges), and if it is not, perform the
adjustment.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list