NSSet(FunkyPrefixedUtilities)

@interface NSSet <__covariant ObjectType>
(FunkyPrefixedUtilities) @end

This extension provides simple and easy to use functional and general utilities for NSSet. All the methods in this category are prefixed with the funky_ keyword for compatibility reasons. If you prefer unprefixed utilities, you should import NSSet+FunkyUtilities.h.

See

Unprefixed counterpart NSSet(FunkyUtilities)

See

Mutable counterpart NSMutableSet(FunkyPrefixedUtilities)
  • Returns whether the condition matches all elements in the set

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) all:]

    Declaration

    Objective-C

    - (BOOL)funky_all:(BOOL (^)(ObjectType))block;

    Swift

    func funky_all(_ block: ((Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    YES if condition matches all elements, NO otherwise

  • Returns whether the condition matches no elements in the set

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) none:]

    Declaration

    Objective-C

    - (BOOL)funky_none:(BOOL (^)(ObjectType))block;

    Swift

    func funky_none(_ block: ((Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    NO if condition matches any of the elements, YES otherwise

  • Returns whether the condition matches at least one element in the set

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) contains:]

    Declaration

    Objective-C

    - (BOOL)funky_contains:(BOOL (^)(ObjectType))block;

    Swift

    func funky_contains(_ block: ((Any?) -> Bool)!) -> Bool

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    YES if condition matches any of the elements, NO otherwise

  • Returns the number of elements the given condition matches in the set, like if you would filter the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) count:]

    Declaration

    Objective-C

    - (NSUInteger)funky_count:(BOOL (^)(ObjectType))block;

    Swift

    func funky_count(_ block: ((Any?) -> Bool)!) -> UInt

    Parameters

    block

    The condition given as a BOOL expression

    Return Value

    Number of occasions where the condition matches in the set

  • Returns a new NSSet instance with the same amount of elements, where each element is transformed to another by returning a new object in the block parameter.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) map:]

    Declaration

    Objective-C

    - (NSSet *)funky_map:(id (^)(ObjectType))block;

    Swift

    func funky_map(_ block: ((Any?) -> Any?)!) -> Set

    Parameters

    block

    The transformator code which should return a new value based on the existing one.

    Return Value

    A new NSSet instance where each element is formed by the result of the block calls

  • Returns a new NSSet instance where each element is transformed to another by returning a new object in the block parameter. It ignores the nil parameters returned from the block.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) nilTolerantMap:]

    Declaration

    Objective-C

    - (NSSet *)funky_nilTolerantMap:(id (^)(ObjectType))block;

    Swift

    func funky_nilTolerantMap(_ block: ((Any?) -> Any?)!) -> Set

    Parameters

    block

    The transformator code which should return a new value based on the existing one.

    Return Value

    A new NSSet instance where each element is formed by the result of the block calls

  • Returns a new NSSet instance with the same amount of elements, where each element is transformed to another by returning a new object in the block parameter. Same as map, but the result is going to be flattened, so if you return an NSSet any iteration, it is going to be converted into a flat structure, not an set of sets.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) flatMap:]

    Declaration

    Objective-C

    - (NSSet *)funky_flatMap:(id (^)(ObjectType))block;

    Swift

    func funky_flatMap(_ block: ((Any?) -> Any?)!) -> Set

    Parameters

    block

    The transformator code which should return a new value based on the existing one.

    Return Value

    A new NSSet instance where each element is formed by the result of the flattened block calls

  • Returns a new NSSet instance with the element, that are passing the returned expression in the original set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) filtered:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_filtered:(BOOL (^)(ObjectType))block;

    Swift

    func funky_filtered(_ block: ((Any?) -> Bool)!) -> Set

    Parameters

    block

    The filtering predicate given as a BOOL expression

    Return Value

    A new NSSet instance where each element is selected from the original one where the block returned YES

  • Flattens the set, meaning that if it consisted of Set items, they are going to be flattened into one flat structure of elements. An set of sets will transform to an set of elements from each of the previous sets. This computation is performed deeply, meaning that it contontued flattening elements, until they produce a flat structure.

    See

    Mutable counterpart -[NSMutableSet(FunkyPrefixedUtilities) funky_flattened]

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) flattened]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_flattened;

    Swift

    func funky_flattened() -> Set

    Return Value

    A new NSSet instance where the elements don’t contain NSSets

  • Takes the union of the two sets.

    See

    Mutable counterpart -[NSMutableSet(FunkyPrefixedUtilities) funky_merge:]

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) merged:]

    Declaration

    Objective-C

    - (NSSet *)funky_takingUnion:(NSSet *)set;

    Swift

    func funky_takingUnion(_ set: Set

    Parameters

    set

    The other collection to union with

    Return Value

    A new NSSet which is the union of the two sets

  • Takes a set which is the current minus the provided one.

    See

    Mutable counterpart -[NSMutableSet(FunkyPrefixedUtilities) funky_merge:]

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) merged:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_takingMinus:(NSSet<ObjectType> *)set;

    Swift

    func funky_takingMinus(_ set: Set

    Parameters

    set

    The other collection to minus with

    Return Value

    A new NSSet which is the minus of the two sets

  • Takes the intersection of the two sets.

    See

    Mutable counterpart -[NSMutableSet(FunkyPrefixedUtilities) funky_merge:]

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) merged:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_takingIntersection:(NSSet<ObjectType> *)set;

    Swift

    func funky_takingIntersection(_ set: Set

    Parameters

    set

    The other collection to intersect with

    Return Value

    A new NSSet which is the intersection of the two sets

  • Calls every element of the set once.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) forEach:]

    Declaration

    Objective-C

    - (void)funky_forEach:(void (^)(ObjectType))block;

    Swift

    func funky_(forEach block: ((Any?) -> Void)!)

    Parameters

    block

    A block, giving the current item in each iteration.

  • Groups elements to an NSDictionary, where the returned element serves as a key, and the objects as the value. If multiple elements are returned with the same key, the result (of which is going to get included) is unpredicatble.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) groupByUsingFirst:]

    Declaration

    Objective-C

    - (NSDictionary<id, ObjectType> *)funky_groupBy:(id (^)(ObjectType))block;

    Swift

    func funky_group(by block: ((Any?) -> Any?)!) -> [AnyHashable : Any]!

    Parameters

    block

    A block which returns a key (based on the passed element) used as the key in the dictionary for that element.

    Return Value

    An NSDictionary where keys are produced by the result of the block call, and the values are the original elements

  • Groups elements to an NSDictionary, where the returned element serves as a key, and the objects as the value. The elements in the resulting Dictionary are sets, so if multiple elements return the same keys, all of them are going to be included in the value.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) associateBy:]

    Declaration

    Objective-C

    - (NSDictionary<id, NSSet<ObjectType> *> *)funky_associateBy:
        (id (^)(ObjectType))block;

    Swift

    func funky_associate(by block: ((Any?) -> Any?)!) -> [AnyHashable : Set

    Parameters

    block

    A block which returns a key (based on the passed element) used as the key in the dictionary.

    Return Value

    An NSDictionary where keys are produced by the result of the blocks, and the values are an set of original elements

  • Produces an aggregated value based on the elements of the set.

    Declaration

    Objective-C

    - (id)funky_reduce:(id (^)(id, ObjectType))block withInitialValue:(id)start;

    Swift

    func funky_reduce(_ block: ((Any?, Any?) -> Any?)!, withInitialValue start: Any!) -> Any!

    Parameters

    start

    The value to start with. At first this is going to be the rolling value.

    block

    The computation logic, which takes the rolling value and the current item and aggregates them using some custom logic.

    Return Value

    A custom value which is produced by computing all the elements with a custom logic, returned in block

  • A special use-case of reduce, which summarises the returned double values for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) sum:]

    Declaration

    Objective-C

    - (double)funky_sum:(double (^)(ObjectType))block;

    Swift

    func funky_sum(_ block: ((Any?) -> Double)!) -> Double

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The sum of all elements, where the numbers are computed are transformed based on the original elements

  • A special use-case of reduce, which takes the average value of the returned double values for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) average:]

    Declaration

    Objective-C

    - (double)funky_average:(double (^)(ObjectType))block;

    Swift

    func funky_average(_ block: ((Any?) -> Double)!) -> Double

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The average of all elements, where the numbers are computed are transformed based on the original elements

  • A special use-case of reduce, which takes the minimum of the returned double values for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) minValue:]

    Declaration

    Objective-C

    - (double)funky_minValue:(double (^)(ObjectType))block;

    Swift

    func funky_minValue(_ block: ((Any?) -> Double)!) -> Double

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The minimum of all elements, where the numbers are computed are transformed based on the original elements

  • A special use-case of reduce, which takes the maximum of the returned double values for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) maxValue:]

    Declaration

    Objective-C

    - (double)funky_maxValue:(double (^)(ObjectType))block;

    Swift

    func funky_maxValue(_ block: ((Any?) -> Double)!) -> Double

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The maximum of all elements, where the numbers are computed are transformed based on the original elements

  • Returns an set with all the minimal value elements in the set, where the minimum was computed by the returned double value for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) minItems:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_minItems:(double (^)(ObjectType))block;

    Swift

    func funky_minItems(_ block: ((Any?) -> Double)!) -> Set

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The set of elements with the minimal value, where the numbers are computed are transformed based on the original elements

  • Returns an set with all the maximal value elements in the set, where the maximum was computed by the returned double value for each element in the set.

    See

    Unprefixed counterpart -[NSSet(FunkyUtilities) maxItems:]

    Declaration

    Objective-C

    - (NSSet<ObjectType> *)funky_maxItems:(double (^)(ObjectType))block;

    Swift

    func funky_maxItems(_ block: ((Any?) -> Double)!) -> Set

    Parameters

    block

    A block which returns double value, based on the current element.

    Return Value

    The set of elements with the maximal value, where the numbers are computed are transformed based on the original elements