Contents

smallestSubset(groupedBy:)

Returns the smallest group of donations when grouped by the specified key path.

Declaration

func smallestSubset<DonationInfo, Value>(groupedBy keyPath: KeyPath<DonationInfo, Value>) -> [Self.Element] where DonationInfo : Decodable, DonationInfo : Encodable, DonationInfo : Sendable, Value : Hashable, Self.Element == Tips.Event<DonationInfo>.Donation

Parameters

  • keyPath:

    A key path to a Hashable property on the donation value to group by.

Return Value

An array of donations belonging to the smallest group.

Discussion

Use this method inside a Tips/Rule predicate to find the least frequently donated value for a given property.

#Rule(LandmarkDetail.didViewLandmarkDetail) {
    $0.donations.smallestSubset(groupedBy: \.landmarkID).count >= 2
}