[swift-users] Why can I not filter or map a dictionary to another dictionary?
Rick Mann
rmann at latencyzero.com
Thu Oct 27 03:00:36 CDT 2016
> On Oct 26, 2016, at 23:43 , Vincent O'Sullivan via swift-users <swift-users at swift.org> wrote:
>
> Ah. Having seen the other answers, I can now see the implied question.
>
> On 27/10/2016, 07:39, "Vincent O'Sullivan via swift-users" <swift-users-bounces at swift.org on behalf of swift-users at swift.org> wrote:
>
> You can. You just need to get the syntax right:
>
> let smallerDictionary = bigDictionary.filter { (key, value) in <some test returning Bool> }
>
> let bd = [1:"A", 2:"B", 3:"C"]
> let sd = bd.filter{(k, v) in
> k > 1}
> dump(sd)
In this example, sd is an array of tuples of (key, value), not a dictionary.
>
> On 27/10/2016, 01:12, "Rick Mann via swift-users" <swift-users-bounces at swift.org on behalf of swift-users at swift.org> wrote:
>
> It seems fairly natural to want to do this:
>
> let bigDictionary = ...
> let smallerDictionary = bigDictionary.filter { key, value in <some test returning Bool> }
>
> Similarly, it seems natural to want to map this way.
>
> Am I overlooking something?
>
> --
> Rick Mann
> rmann at latencyzero.com
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
--
Rick Mann
rmann at latencyzero.com
More information about the swift-users
mailing list