Reduce with inout

Should combine be allowed to throw, thus forcing this method to rethrow?

------------ Begin Message ------------
Group: gmane.comp.lang.swift.evolution
MsgID: <CAJiQnkQcyhZvRF=TGCs6h8CHPQcbO4gpym63qMzBU4FW9S9T5w@mail.gmail.com>

I like it too! Thanks Pyry! Will change the proposal.

···

On Wed, Jan 25, 2017 at 8:09 AM, David Hart via swift-evolution < swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

Yep, that's really good.

On 25 Jan 2017, at 08:00, Jonathan Hull via swift-evolution < >swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

+1 Best so far.

On Jan 24, 2017, at 10:36 AM, Pyry Jahkola via swift-evolution < >swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

Freak Show wrote:

Am I the only one who finds this incredibly ugly and hard to read?

This is more or less solved by inject:into: idiom. There is no reason for
inout for this particular problem.

Yeah, the original signature seems more useful. If you go all `inout` like
Gwendal suggested, you might as well just iterate over the sequence with
`for x in xs`, updating the state as you go.

But your comment brought another idea to mind: if `mutating:` is
considered a bad name for a non-`inout` argument, how about `
*reduce(into:combine:)`*, similar to what Karl suggested earlier in this
thread?

I think it reads very well at the call site, does not suggest `inout`ness
of the argument too much (of course there's no `&` at the call site
either), and it's still easily found with auto-completion:

let counts = words.reduce(into: [:]) {
$0[$1] = ($0[$1] ?? 0) + 1
}

— Pyry
_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

------------- End Message -------------

Sent from my iPad

Apologies if this reply comes across the list multiple times...

Should combine be allowed to throw, thus forcing this method to rethrow?

···

------------ Begin Message ------------
Group: gmane.comp.lang.swift.evolution
MsgID: <CAJiQnkQcyhZvRF=TGCs6h8CHPQcbO4gpym63qMzBU4FW9S9T5w@mail.gmail.com>

I like it too! Thanks Pyry! Will change the proposal.

On Wed, Jan 25, 2017 at 8:09 AM, David Hart via swift-evolution < > swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

Yep, that's really good.

On 25 Jan 2017, at 08:00, Jonathan Hull via swift-evolution < >> swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

+1 Best so far.

On Jan 24, 2017, at 10:36 AM, Pyry Jahkola via swift-evolution < >> swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org> wrote:

Freak Show wrote:

Am I the only one who finds this incredibly ugly and hard to read?

This is more or less solved by inject:into: idiom. There is no reason for
inout for this particular problem.

Yeah, the original signature seems more useful. If you go all `inout` like
Gwendal suggested, you might as well just iterate over the sequence with
`for x in xs`, updating the state as you go.

But your comment brought another idea to mind: if `mutating:` is
considered a bad name for a non-`inout` argument, how about `
*reduce(into:combine:)`*, similar to what Karl suggested earlier in this
thread?

I think it reads very well at the call site, does not suggest `inout`ness
of the argument too much (of course there's no `&` at the call site
either), and it's still easily found with auto-completion:

let counts = words.reduce(into: [:]) {
$0[$1] = ($0[$1] ?? 0) + 1
}

— Pyry
_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org
https://lists.swift.org/mailman/listinfo/swift-evolution

------------- End Message -------------

Sent from my iPad