{"id":18463918,"url":"https://github.com/badchoice/collection","last_synced_at":"2025-08-17T01:13:06.178Z","repository":{"id":48503570,"uuid":"61222907","full_name":"BadChoice/Collection","owner":"BadChoice","description":"Laravel collection like inspired NSArray category","archived":false,"fork":false,"pushed_at":"2023-06-28T06:55:29.000Z","size":200,"stargazers_count":21,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-18T19:16:44.949Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BadChoice.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-15T16:24:30.000Z","updated_at":"2023-06-28T06:51:16.000Z","dependencies_parsed_at":"2024-06-19T23:09:49.587Z","dependency_job_id":"7db4055e-0711-4bcf-ad9c-a94eb5318ed9","html_url":"https://github.com/BadChoice/Collection","commit_stats":{"total_commits":135,"total_committers":6,"mean_commits":22.5,"dds":0.2666666666666667,"last_synced_commit":"beac79eef4b858334249de0ca16ef6f88b0ef4c9"},"previous_names":[],"tags_count":88,"template":false,"template_full_name":null,"purl":"pkg:github/BadChoice/Collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FCollection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FCollection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FCollection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FCollection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BadChoice","download_url":"https://codeload.github.com/BadChoice/Collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BadChoice%2FCollection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270794964,"owners_count":24646951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T09:08:21.976Z","updated_at":"2025-08-17T01:13:06.137Z","avatar_url":"https://github.com/BadChoice.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NSArray+Collection\n\n**Never write another loop again**   \n\nThis library is inspired by `Laravel` collection class to use its expressive syntax.\nCheck the .h file to see the documentation as well as all available methods.\n\n\n## Installation\nCopy the category files to your project or just\n\n```ruby\npod 'Collection' \n```\n\n## Array available methods\n\n`each:block`\n`eachWithIndex:blockWithIndex`\n`map:block`\n`flatMap:block`\n`flatMap:key:block`\n\n`filter:blockChecker` \n`filterWith:keyPath` \n`reject:blockChecker` \n`rejectWith:keyPath` \n`first:blockChecker` \n`first:blockChecker:default` \n`first:blockChecker:defaultBlock`\n`last:blockChecker` \n`last:blockChecker:default` \n`contains:blockChecker` \n`doesntContain:blockChecker` \n`where:keyPath:like` \n`where:keyPath:is` \n`where:keyPath:isNot` \n`whereAny:keyPaths:like` \n`whereAny:keyPaths:is` \n`whereNull` \n`whereNull:keyPath` \n`whereNotNull`\n`whereNotNull:keyPath` \n`whereIn:keyPath:values`\n\n`sort`\n`sort:key`\n`sort:key:ascending`\n`sortWith:block:ascending`\n\n`reverse`\n`random:quantity`\n`slice:howMany`\n`take:howMany`\n`splice:howMany`\n`pop`\n\n`pluck:keyPath`\n`pluck:keyPath:keyKeyPath`\n`flatten`\n`flatten:keyPath`\n`partition:block`\n`reduce:block`\n`reduce:block:initialCarry`\n`pipe:block`\n`when:condition:block`\n`groupBy:keyPath`\n`gorupBy:keyPath:block`\n`expand:keypath`\n\n`maxObject`\n`maxObject:keyPath`\n`maxObjectFor:block`\n`minObject`\n`minObject:keyPath`\n`minObjectFor:block`\n\n`suffled`\n`permutations`\n`zip:other`\n`mapToAssoc:block`\n`countedSet`\n`implode:glue`\n`toString`\n`toJson`\n\n`intersect:other`\n`union:other`\n`join:other`\n`diff:other`\n`minus:other`\n`minusExactOcurrences:other`\n`distinct`\n`distinct:keypath`\n\n`range:to`\n`range:from:to`\n\n`times:times:value`\n`times:times:callback`\n\n`crossJoin:list`\n`cartesianProduct:arrays`\n\n`sum`\n`sum:keyPath`\n`sumWith:block`\n`avg`\n`avg:keyPath`\n`max`\n`max:keyPath`\n`min`\n`min:keyPath`\n`countKeyPath:`\n\n`map_:selector`\n`map_:selector:withObject`\n`each_:selector`\n`each_:selector:withObject`\n`filter_:selector`\n`filter_:selector:withObject`\n`reject_:selector`\n`reject_:selector:withObject`\n\n## Dictionary available methods\n`fromData:data`\n`fromString:string`\n`toString`\n`except:keys`\n`only:keys`\n\n`each:block`\n`filter:block`\n`filter:block`\n`map:block`\n\n## String available methods\n`repeat:text:times`\n`isEmptyString`\n`explode:delimiter`\n`initials`\n`toNumber`\n`append:other`\n`prepend:other`\n`substr:from`\n`substr:from:length`\n`replace:text:with`\n`replaceRegexp:regexp:with`\n`split`\n`split:lenght`\n`trim`\n`trimWithNewLine`\n`trimLeft`\n`trimRight`\n`camelCase`\n`pascalCase`\n`snakeCase`\n`ucFirst`\n`withoutDiacritic`\n`urlEncode`\n`urlDecode`\n`md5`\n`toBase64`\n`fromHex:str`\n`toHex`\n\n`endsWith:text`\n`startsWith:text`\n`contains:text`\n`matches:regexp`\n\n`lpad:length:text`\n`rpad:length:text`\n\n## Array Examples\n\nJust some examples, check the .h or the tests to see them all\nIn the .h there is the explanation of what it really does\n\n\n```objc\nNSArray* array = @[@1,@3,@4,@5,@6];\nNSNumber* first = [array first:^BOOL(NSNumber* object) {\n    return object.intValue \u003e 4;\n}];\nNSLog(@\"Fist: %@\",first);\n```\n\n```objc\nNSNumber* second = [array first:^BOOL(NSNumber* object) {\n    return object.intValue \u003e 10;\n} default:@25];\nNSLog(@\"second: %@\",second);\n```\n\n```objc\nNSArray* oldHeroes = [self.heroes reject:^BOOL(Hero *object) {\n    return object.age.intValue \u003c 20;\n}];\n[self printHeroArray:oldHeroes];\n```\n\n```objc\n[self printHeroArray:[self.heroes map:^id(Hero* obj, NSUInteger idx) {\n    obj.age = @(obj.age.intValue * 2);\n    return obj;\n}]];\n[self printArray:[self.heroes pluck:@\"enemy\"]];\n```\n\n```objc\nNSNumber* totalAge = [self.heroes reduce:^id(NSNumber* carry, Hero* object) {\n    return @(object.age.intValue + carry.intValue);\n} carry:@(0)];\n\n// or\n\nNSNumber* totalAge2 = [self.heroes sum:@\"age\"];\n```\n\n```objc\nNSNumber* age = [self.heroes sum:@\"age\"];\nNSLog(@\"Age again: %@\",age);\n\nNSNumber* older = [self.heroes max:@\"age\"];\nNSLog(@\"older: %@\",older);\n\nNSNumber* younger = [self.heroes min:@\"age\"];\nNSLog(@\"younger: %@\",younger);\n\nNSNumber* average = [self.heroes avg:@\"age\"];\nNSLog(@\"average: %@\",average);\n```\n\n```objc\n[self printArray:[@[@1,@2,@3,@4] union:@[@4,@5,@6]]];\n[self printArray:[@[@1,@2,@3,@4] intersect:@[@4,@5,@6]]];\n[self printArray:[@[@1,@2,@3,@4] join:@[@4,@5,@6]]];\n[self printArray:[@[@1,@2,@3,@4] diff:@[@4,@5,@6]]];\n```\n\n```objc\n[self.heroes groupBy:@\"age\"];\n\n[self.heroes groupBy:@\"age\" block:^NSString *(Hero *object, NSString *key) {\n    return str(@\"age %@\", object.age);\n}];\n```\n\n```objc\nNSArray* names = @[\"Spiderman\", @\"Batman\", @\"Robin\", @\"Luxor\"];\nBOOL containsSpiderman = [self.names contains:^BOOL(Hero* hero) {\n    return [hero.name isEqualToString:@\"Spiderman\"];\n}];\n\nBOOL heroes = [self.names where:@\"name\" like:@\"man\"];\n// heroes =\u003e [@\"Spiderman, @\"Batman\"] \n```\n\n\n```objc\n[@[@1,@2,@3,@4,@5,@6] slice:3];\n[@[@1,@2,@3,@4,@5,@6] slice:10];\n[@[@1,@2,@3,@4,@5,@6] slice:6];\n[@[@1,@2,@3,@4,@5,@6] take:2];\n[@[@1,@2,@3,@4,@5,@6] take:10];\n[@[@1,@2,@3,@4,@5,@6] take:-2];\n[@[@1,@2,@3,@4,@5,@6] take:-10];\n```\n\n```objc\nNSArray* array2 = @[@1,@2,@3,@4,@5].mutableCopy;\nNSArray* chunk = [array2 splice:2];\n[self printArray:chunk];\n[self printArray:array2];\n```\n\n## Dictionary Examples\n\nJust some examples, check the .h or the tests to see them all\n    \n```objc\nNSDictionary* filtered = [@{@\"pass\":@0, @\"dontPass\":@1} filter:^BOOL(id key, id object) {\n    return object.floatValue == 0;\n}];\n```\n\n```objc\nNSDictionary* result = [@{@\"toBeMapped\":@\"value\", @\"toBeMapped2\":@\"value2\"} map:^id(id key, id object) {\n    return [key append:object];\n}];\n```\n\n## String Examples\n\nJust some examples, check the .h or the tests to see them all\n\n```objc\n// [NSString stringWithFormat:@\"a formated %@ string\", value]; \n// becomes\nstr(@\"a formated %@ string\", value);\n```\n\n```objc\nNSArray* result         = [@\"hola;que;tal\" explode:@\";\"];\nNSArray* expectation    = @[@\"hola\",@\"que\",@\"tal\"];\nXCTAssertTrue([result isEqual:expectation]);\n```\n\n```objc\nNSString* result = [@\"   trim   \" trim];\nXCTAssertTrue( [result isEqualToString:@\"trim\"]);\n```\n\n```objc\nNSString* result = @\"this should be camelcased\".camelCase;\nXCTAssertTrue( [result isEqualToString:@\"thisShouldBeCamelcased\"]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadchoice%2Fcollection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadchoice%2Fcollection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadchoice%2Fcollection/lists"}