Skip to content

[question] linq_aggregate API to avoid boxing? #12

@dodikk

Description

@dodikk

Are you planning to add linq_aggregate API for primitive types?

    NSNumber* totalCount = [shoppingCart linq_aggregate: ^NSNumber*(id<MyCommodity> item, NSNumber* aggregate)
    {
        NSNumber* orderedItemsCount = [item numberOfOrders];
        NSUInteger newResult = [orderedItemsCount unsignedIntegerValue] + [aggregate unsignedIntegerValue];

        return @(newResult);
    }];

In this example there is a lot of boxing/unboxing (NSNumber ==> NSUInteger ==> NSNumber) which is a good thing to avoid.

P.S. I know that integers can be "safely" casted to id. But I strongly dislike this approach. Moreover, it does not work for [NSNumber floatValue].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions