Skip to content

Commit fe94c36

Browse files
authored
Merge pull request #153 from lorentey/issue145
[OrderedDictionary][doc] Update docs for merge/filter operations
2 parents 20e7fce + 6cb0370 commit fe94c36

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

Sources/OrderedCollections/OrderedDictionary/OrderedDictionary.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -767,14 +767,18 @@ extension OrderedDictionary {
767767
///
768768
/// // Keeping existing value for key "a":
769769
/// dictionary.merge(zip(["a", "c"], [3, 4])) { (current, _) in current }
770-
/// // ["b": 2, "a": 1, "c": 4]
770+
/// // ["a": 1, "b": 2, "c": 4]
771771
///
772772
/// // Taking the new value for key "a":
773773
/// dictionary.merge(zip(["a", "d"], [5, 6])) { (_, new) in new }
774-
/// // ["b": 2, "a": 5, "c": 4, "d": 6]
774+
/// // ["a": 5, "b": 2, "c": 4, "d": 6]
775+
///
776+
/// This operation preserves the order of keys in the original dictionary.
777+
/// New key-value pairs are appended to the end in the order they appear in
778+
/// the given sequence.
775779
///
776780
/// - Parameters:
777-
/// - other: A sequence of key-value pairs.
781+
/// - keysAndValues: A sequence of key-value pairs.
778782
/// - combine: A closure that takes the current and new values for any
779783
/// duplicate keys. The closure returns the desired value for the final
780784
/// dictionary.
@@ -813,14 +817,18 @@ extension OrderedDictionary {
813817
///
814818
/// // Keeping existing value for key "a":
815819
/// dictionary.merge(zip(["a", "c"], [3, 4])) { (current, _) in current }
816-
/// // ["b": 2, "a": 1, "c": 4]
820+
/// // ["a": 1, "b": 2, "c": 4]
817821
///
818822
/// // Taking the new value for key "a":
819823
/// dictionary.merge(zip(["a", "d"], [5, 6])) { (_, new) in new }
820-
/// // ["b": 2, "a": 5, "c": 4, "d": 6]
824+
/// // ["a": 5, "b": 2, "c": 4, "d": 6]
825+
///
826+
/// This operation preserves the order of keys in the original dictionary.
827+
/// New key-value pairs are appended to the end in the order they appear in
828+
/// the given sequence.
821829
///
822830
/// - Parameters:
823-
/// - other: A sequence of key-value pairs.
831+
/// - keysAndValues: A sequence of key-value pairs.
824832
/// - combine: A closure that takes the current and new values for any
825833
/// duplicate keys. The closure returns the desired value for the final
826834
/// dictionary.
@@ -854,9 +862,9 @@ extension OrderedDictionary {
854862
/// let newKeyValues = zip(["a", "b"], [3, 4])
855863
///
856864
/// let keepingCurrent = dictionary.merging(newKeyValues) { (current, _) in current }
857-
/// // ["b": 2, "a": 1]
865+
/// // ["a": 1, "b": 2]
858866
/// let replacingCurrent = dictionary.merging(newKeyValues) { (_, new) in new }
859-
/// // ["b": 4, "a": 3]
867+
/// // ["a": 3, "b": 4]
860868
///
861869
/// - Parameters:
862870
/// - other: A sequence of key-value pairs.
@@ -865,7 +873,9 @@ extension OrderedDictionary {
865873
/// dictionary.
866874
///
867875
/// - Returns: A new dictionary with the combined keys and values of this
868-
/// dictionary and `other`.
876+
/// dictionary and `other`. The order of keys in the result dictionary
877+
/// matches that of `self`, with additional key-value pairs (if any)
878+
/// appended at the end in the order they appear in `other`.
869879
///
870880
/// - Complexity: Expected to be O(`count` + *n*) on average, where *n* is the
871881
/// number of elements in `keysAndValues`, if `Key` implements high-quality
@@ -897,9 +907,9 @@ extension OrderedDictionary {
897907
/// let newKeyValues = zip(["a", "b"], [3, 4])
898908
///
899909
/// let keepingCurrent = dictionary.merging(newKeyValues) { (current, _) in current }
900-
/// // ["b": 2, "a": 1]
910+
/// // ["a": 1, "b": 2]
901911
/// let replacingCurrent = dictionary.merging(newKeyValues) { (_, new) in new }
902-
/// // ["b": 4, "a": 3]
912+
/// // ["a": 3, "b": 4]
903913
///
904914
/// - Parameters:
905915
/// - other: A sequence of key-value pairs.
@@ -908,7 +918,9 @@ extension OrderedDictionary {
908918
/// dictionary.
909919
///
910920
/// - Returns: A new dictionary with the combined keys and values of this
911-
/// dictionary and `other`.
921+
/// dictionary and `other`. The order of keys in the result dictionary
922+
/// matches that of `self`, with additional key-value pairs (if any)
923+
/// appended at the end in the order they appear in `other`.
912924
///
913925
/// - Complexity: Expected to be O(`count` + *n*) on average, where *n* is the
914926
/// number of elements in `keysAndValues`, if `Key` implements high-quality
@@ -932,7 +944,8 @@ extension OrderedDictionary {
932944
/// argument and returns a Boolean value indicating whether the pair
933945
/// should be included in the returned dictionary.
934946
///
935-
/// - Returns: A dictionary of the key-value pairs that `isIncluded` allows.
947+
/// - Returns: A dictionary of the key-value pairs that `isIncluded` allows,
948+
/// in the same order that they appear in `self`.
936949
///
937950
/// - Complexity: O(`count`)
938951
@inlinable
@@ -956,7 +969,7 @@ extension OrderedDictionary {
956969
/// accepts each value of the dictionary as its parameter and returns a
957970
/// transformed value of the same or of a different type.
958971
/// - Returns: A dictionary containing the keys and transformed values of
959-
/// this dictionary.
972+
/// this dictionary, in the same order.
960973
///
961974
/// - Complexity: O(`count`)
962975
@inlinable
@@ -991,7 +1004,7 @@ extension OrderedDictionary {
9911004
/// optional transformed value of the same or of a different type.
9921005
///
9931006
/// - Returns: A dictionary containing the keys and non-`nil` transformed
994-
/// values of this dictionary.
1007+
/// values of this dictionary, in the same order.
9951008
///
9961009
/// - Complexity: O(`count`)
9971010
@inlinable

0 commit comments

Comments
 (0)