[go: up one dir, main page]

Skip to content
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

Add reductions(_:_:) #46

Merged
merged 45 commits into from
Mar 24, 2021
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4bba172
Add scan function
danielctull Oct 9, 2020
548b1e7
Add initial conditional conformances to Collection and BidirectionalC…
danielctull Nov 24, 2020
e9edde0
Rename scan to reductions
danielctull Nov 24, 2020
b41af13
Add information to the readme about the reductions name
danielctull Nov 24, 2020
5116e25
Add eager API
danielctull Nov 25, 2020
e9d35f6
Remove Reductions' conformance to BidirectionalCollection
danielctull Nov 26, 2020
caf0b71
Implement Reductions subscript such that it occurs in constant time
danielctull Nov 26, 2020
531b6f9
Add a variant which includes the given initial result
danielctull Nov 26, 2020
c0c237a
Add a variant which takes no initial result value
danielctull Nov 26, 2020
7bb96ea
Add excluding label to show the initial result is not included
danielctull Nov 26, 2020
5b4d984
Test lazy implementations
danielctull Nov 26, 2020
e0ee01d
Remove reductions(including:_:)
danielctull Nov 26, 2020
1ce31ed
Add conformance to LazySequenceProtocol and LazyCollectionProtocol wh…
danielctull Nov 26, 2020
fe912e5
Fix implementation of lazy reductions
danielctull Nov 27, 2020
c3e918d
Add test cases for sequences with one element
danielctull Nov 27, 2020
c693579
Tidy up tests
danielctull Nov 27, 2020
55e87eb
Improve ergonomics of no initial value eager reductions call and prov…
danielctull Nov 27, 2020
4654ae7
Add lazy InclusiveReductions sequence
danielctull Nov 27, 2020
154fa40
Rename Reductions to ExclusiveReductions
danielctull Nov 27, 2020
959e963
Add Collection implementation for InclusiveReductions
danielctull Nov 27, 2020
0c60ad7
Update guide
danielctull Nov 27, 2020
2a41ecb
Add links for C++ implementations
danielctull Nov 27, 2020
aac96c3
Add conformance to Collection for ExclusiveReductions
danielctull Nov 28, 2020
a61878f
Improve ergonomics of ExclusiveReductions' index representation
danielctull Nov 28, 2020
058edc8
Improve ergonomics of InclusiveReductions' index representation by sh…
danielctull Nov 29, 2020
a221997
Tidy up internal function
danielctull Nov 29, 2020
ab40e33
Add exclusive eager version of reductions(into:_:)
danielctull Nov 29, 2020
6b01737
Use new lazy assertion functions
danielctull Dec 3, 2020
714f46b
Correct the complexity claims for reductions
danielctull Feb 25, 2021
5182363
Separate the index types
danielctull Feb 25, 2021
84b6ddc
Update guide to reflect that arrays are returned directly
danielctull Mar 8, 2021
fb004f7
Add scan as deprecated methods
danielctull Mar 8, 2021
7464876
Add lazy overload of reductions(into:_:)
danielctull Mar 18, 2021
174efb8
Add the reductions(into:_:) functions
danielctull Mar 18, 2021
1e47f86
More succinctly introduce reductions
danielctull Mar 18, 2021
a73c681
Add a note about the deprecated scan functions
danielctull Mar 18, 2021
f6b42ad
Update documentation
danielctull Mar 18, 2021
f7b90b5
Add @inlinable and @usableFromInline
danielctull Mar 18, 2021
e9abcdb
Copy documentation to all variants of reductions
danielctull Mar 19, 2021
04f0a23
Test the value after the function is complete
danielctull Mar 19, 2021
724e223
Just use the += operator
danielctull Mar 19, 2021
042013f
Add an example for reductions(into:_:)
danielctull Mar 19, 2021
5f55e8b
Improve the documentation of the return value
danielctull Mar 21, 2021
d4daf2c
Update complexity note
danielctull Mar 22, 2021
6660d64
Use the reduce documentation for inspiration for the discussion of re…
danielctull Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use the reduce documentation for inspiration for the discussion of re…
…ductions
  • Loading branch information
danielctull committed Mar 22, 2021
commit 6660d642cdc0093b19ca20cdb2845faa79b83767
44 changes: 44 additions & 0 deletions Sources/Algorithms/Reductions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ extension Sequence {
/// // prints [0, 1, 3, 6, 10]
/// ```
///
/// When `reductions(_:_:)` is called, the following steps occur:
///
/// 1. The `initial` result is added to an array of results.
/// 2. The `transform` closure is called with the `initial` result and the
/// first element of the sequence, appending the result to the array.
/// 3. The closure is called again repeatedly with the updated accumulating
/// result and each element of the sequence, adding each result to the
/// array.
/// 4. When the sequence is exhausted, the results array is returned to the
/// caller.
///
/// If the sequence has no elements, `transform` is never executed and
/// an array containing only the `initial` result is returned.
///
/// - Parameters:
/// - initial: The value to use as the initial value.
/// - transform: A closure that combines the previously reduced result and
Expand Down Expand Up @@ -123,6 +137,20 @@ extension Sequence {
/// // prints [0, 1, 3, 6, 10]
/// ```
///
/// When `reductions(into:_:_)` is called, the following steps occur:
///
/// 1. The `initial` result is added to an array of results.
/// 2. The `transform` closure is called with the `initial` result and the
/// first element of the sequence, appending the result to the array.
/// 3. The closure is called again repeatedly with the updated accumulating
/// result and each element of the sequence, adding each result to the
/// array.
/// 4. When the sequence is exhausted, the results array is returned to the
/// caller.
///
/// If the sequence has no elements, `transform` is never executed and
/// an array containing only the `initial` result is returned.
///
/// - Parameters:
/// - initial: The value to use as the initial value.
/// - transform: A closure that combines the previously reduced result and
Expand Down Expand Up @@ -347,6 +375,22 @@ extension Sequence {
/// // prints [1, 3, 6, 10]
/// ```
///
/// When `reductions(_:)` is called, the following steps occur:
///
/// 1. The `transform` closure is called with the first and second elements
/// of the sequence, appending the result to an array of results.
/// 2. The closure is called again repeatedly with the updated accumulating
/// result and the next element of the sequence, adding each result to the
/// array.
/// 3. When the sequence is exhausted, the results array is returned to the
/// caller.
///
/// If the sequence has no elements, `transform` is never executed and
/// an empty array is returned.
///
/// If the sequence has one element, `transform` is never executed and
/// an array containing only that first element is returned.
///
/// - Parameters:
/// - transform: A closure that combines the previously reduced result and
/// the next element in the receiving sequence.
Expand Down