Skip to content

[swift-4.0-branch] Implement SE-0171: Reduce with inout #11135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2017

Conversation

moiseev
Copy link
Contributor

@moiseev moiseev commented Jul 24, 2017

  • Explanation: This change implements SE-0171 which was accepted for Swift 4
  • Scope of Issue: Additive change that enables more optimal and more idiomatic use of reduce
  • Risk: Minimal as change is additive
  • Reviewed By: Dave Abrahams
  • Testing: Automated test suite with an extra test cases for the added functionality
  • Directions for QA: N/A
  • Radar: rdar://problem/33490856

Implement and document `reduce(into:_:)`, with a few notes:

 - The `initial` parameter was renamed `initialResult` to match the first parameter in `reduce(_:_:)`.
 - The unnamed `combining` parameter was renamed `updateAccumulatingResult` to try and resemble the naming of the closure parameter in `reduce(_:_:)`.
 - The closure throws and `reduce(into:_)` re-throws.
 - This documentation mentions that `reduce(into:_)` is preferred over `reduce(_:_:)` when the result is a copy-on-write type and an example where the result is a dictionary.

Add benchmarks for reduce with accumulation into a scalar, an array, and a dictionary.

Update expected error message in closures test (since there are now two `reduce` methods, the diagnostic is different).
This checks:
 - The examples from the documentation of `reduce(_:_:)` and `reduce(into:_:)`.
 - Different levels of inference in the closure arguments being passed.
 - That the value passed as the `initialResult` remains unmodified.
The ReduceInto benchmark performs three tasks using both `reduce(_:_)` and `reduce(into:_:)` so that their performance can be compared:

1. Summing an array, reducing to `Int`
2. Filtering an array, reducing to `[Int]`
3. Counting letter frequencies, reducing to `[Character: Int]`
@moiseev
Copy link
Contributor Author

moiseev commented Jul 24, 2017

@swift-ci Please test

@moiseev
Copy link
Contributor Author

moiseev commented Jul 24, 2017

@swift-ci Please Test Source Compatibility

@moiseev
Copy link
Contributor Author

moiseev commented Jul 24, 2017

4.0 version of #10976
/cc @d-ronnqvist

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - cbba7c7
Test requested by - @moiseev

@moiseev
Copy link
Contributor Author

moiseev commented Jul 24, 2017

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - cbba7c7
Test requested by - @moiseev

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - cbba7c7
Test requested by - @moiseev

@airspeedswift airspeedswift merged commit 7ba7a7f into swiftlang:swift-4.0-branch Jul 24, 2017
@moiseev moiseev deleted the reduce-inout-4 branch July 24, 2017 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants