[swift-users] Appending '[element]' recursively

Adriano Ferreira adriano.ferreira at me.com
Mon Jun 27 12:14:17 CDT 2016


Thanks Dmitri.

If use typecasting it seems to work again. Take a look below:

// Swift 3

func quickSort(_ array: [Int]) -> [Int] {
    guard array.count > 1 else {
        return array
    }

    let (pivot, rest) = (array.first!, array.dropFirst())

    let lessThan = rest.filter({ $0 < pivot })
    let greaterThanOrEqual = rest.filter({ $0 >= pivot })

    // If I typecast ‘[pivot]’ to ‘[Int]' it now works
    return quickSort(lessThan) + ([pivot] as [Int]) + quickSort(greaterThanOrEqual)
}

Cheers,

— A

> On Jun 27, 2016, at 1:01 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
> On Mon, Jun 27, 2016 at 9:44 AM, Adriano Ferreira
> <adriano.ferreira at me.com> wrote:
>> 
>> Here the exact error I’m getting:
> 
> I see.  I think this is a compiler bug, I filed
> https://bugs.swift.org/browse/SR-1914 .  Thanks!
> 
> 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>*/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160627/17d9a087/attachment.html>


More information about the swift-users mailing list