{"id":18270859,"url":"https://github.com/acburk/SOCQ","last_synced_at":"2025-04-05T01:30:52.974Z","repository":{"id":2386183,"uuid":"3351905","full_name":"acburk/SOCQ","owner":"acburk","description":"Syntax for Objective-C Queries","archived":false,"fork":false,"pushed_at":"2017-04-16T21:46:27.000Z","size":81,"stargazers_count":310,"open_issues_count":0,"forks_count":24,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-18T16:55:50.565Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acburk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-04T09:42:47.000Z","updated_at":"2024-12-18T11:57:27.000Z","dependencies_parsed_at":"2022-09-09T04:11:47.545Z","dependency_job_id":null,"html_url":"https://github.com/acburk/SOCQ","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acburk%2FSOCQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acburk%2FSOCQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acburk%2FSOCQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acburk%2FSOCQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acburk","download_url":"https://codeload.github.com/acburk/SOCQ/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276043,"owners_count":20912286,"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","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-05T11:38:54.850Z","updated_at":"2025-04-05T01:30:52.596Z","avatar_url":"https://github.com/acburk.png","language":"Objective-C","readme":"# SOCQ (Syntax for Objective-C Queries)\n\nBringin' some query love to Objective-C\n\nFeel free to open issues(feature requests), fork, and/or open pull requests!\n\n(MIT license, details at the bottom of this file or in the MIT-License.txt file.)\n\n__NSArray__\n\n- skip:\n- take:\n- skip:take:\n- where:\n- any:\n- all:\n- groupby:\n- distinctObjectsByAddress\n- distinct\n- select:\n- selectKeypaths:\n- firstObject\n- secondObject\n\n__NSMutableArray__\n\n- popObjectAtIndex:\n- popFirstObject\n- popLastObject\n\n__NSDictionary__\n\n- where:\n- any:\n- all:\n\n__NSSet__\n\n- where:\n- any:\n- all:\n- groupby:\n- select:\n- selectKeypaths:\n\n## NSArray\n#### take:\n```objc\n- (NSArray*)take:(NSUInteger)inCount;\n```\t\n_Returns an array with the specified number of elements from the beginning of the target array._\n\n```objc\n// Example - Getting the first five elements\n\t\nNSArray* elements = [people take:5];\n```\n\n#### skip:\n```objc\n- (NSArray*)skip:(NSUInteger)inCount;\n```\n\n_Skips the indicated number of elements in the array and returns an array of the remaining elements._\n\n```objc\n// Example - skips the first five elements\n\nNSArray* remaining = [people skip:5];\n```\n\n#### skip:take:\n```objc\n- (NSArray*)skip:(NSUInteger)inSkip take:(NSUInteger)inTake;\n```\n\n_Simple convenience method that combines the skip and take methods. Ideal for pagination._\n\t\n```objc\n// Example - get elements 6-10\n\t\nNSArray* remaining = [people skip:5 take:5];\n```\t\n\t\n#### where:\n```objc\n- (NSArray*)where:(BOOL(^)(id obj))check;\n```\n\n_Uses the `check` block on every element in the array to determine if they should be returned in the return array_\n\n```objc\n// Example - find people that are 25 years old\n\t\nNSArray* 25YearOlds = [people where:^(id obj){ return [obj age] == 25; }];\n```\n\n#### any:\n```objc\n- (BOOL)any:(BOOL(^)(id obj))check;\n```\n\n_Checks every element in the array to see if any of the elements successfully pass the `check` block. If none pass, return `NO`, else `YES`._\n\n```objc\n// Example - check to see if anyone is under 18\n\nBOOL containsMinors = [people any:^(id obj){ return [obj age] \u003c 18; }];\n```\n\n#### all:\n```objc\n- (BOOL)all:(BOOL(^)(id obj))check;\n```\n\n_Checks every element in the array to see if all of the elements successfully pass the `check` block. If all elements pass, return `YES`, else `NO`._\n\n```objc\n// Example - check to see if everyone is 25 or over\n\nBOOL everyone25orOver = [people all:^(id obj){ return [obj age] \u003e= 25; }];\n```\n\n#### groupby:\n```objc\n- (NSDictionary*)groupBy:(id(^)(id obj))groupBlock;\n```\n_Uses the object returned from the `groupBlock` block as a key to group the object into a NSDictionary that contains a NSArray with all the objects that returned the same key_\n\n```objc\n// Example - group everyone by their last name\n\nNSDictionary* peopleByFamilyName = [people groupBy:^(id obj){ return [obj lastName]; }];\n```\n#### distinctObjectsByAddress\n```objc\n- (NSArray*)distinctObjectsByAddress;\n```\n_Does a simple pointer address compare to remove elements that refer to the same object_\n\n```objc\n// Example - remove the exact same elements\n\nNSArray* uniquePeople = [people distinctObjectsByAddress];\n```\n#### distinct\n```objc\n- (NSArray*)distinct;\n```\n_Uses the class' compare and hash method to remove elements that contain the same value_\n\n```objc\n// Example - remove the exact same elements\n\nNSArray* uniquePeople = [people distinct];\n```\n#### select:\n```objc\n- (NSArray*)select:(id(^)(id originalObject))transform;\n```\t\n_Transforms elements in the array into another strongly type object that is returned from the `transform` block._\n\n```objc\n// Example - Change people objects into American Class objects\n\nNSArray* americans = [people select:^(id obj){ return [[American alloc] initWithFirstName:[obj firstName]\n\t\t\t\t\t\t\t\t\t\t LastName:[obj lastName]\n\t\t\t\t\t\t\t\t\t\t      age:[obj age]] }];\n```\n#### selectKeypaths:\n```objc\n- (NSArray*)selectKeypaths:(NSString*)keypath, ... NS_REQUIRES_NIL_TERMINATION;\n```\n_Selects properties from the elements in the array using the keypath mechanism. Any number of keypaths maybe specified but the list must be `nil` terminated. The return value is an array of dictionaries. The dictionary contain the keypaths that were passed in as the parameters as the keys and the valueForKeyPath: as the values._\n\n```objc\n// Example - Get the four properties we need from the person object\n\nNSArray* americans = [people selectKeypaths:@\"firstName\",@\"lastName\",@\"parent.firstName\",@\"age\",nil];\n```\n#### firstObject\n```objc\n- (id)firstObject;\n```    \n_Returns the first object in the array. If the array is empty, returns nil._\n\n```objc\n// Example - Get the first person\n    \nid person = [people firstObject];\n```\n#### secondObject\n```objc\n- (id)secondObject;\n```    \n_Returns the second object in the array. If the array doesn't contain two objects, returns nil._\n\n```objc\n// Example - Get the second person\n    \nid person = [people secondObject];\n```\n\n## NSMutableArray\n#### popObjectAtIndex:\n```objc\n- (id)popObjectAtIndex:(NSUInteger)inIndex;\n```\n#### popFirstObject\n```objc\n- (id)popFirstObject;\n```\n#### popLastObject\n```objc\n- (id)popLastObject;\n```\n\n_Removes and returns the object from the array. If index is outside out the range of the array, `NSRangeException` is raised._\n\n```objc\n// Example - remove the first person from the array\nPerson* firstPerson = [people popFirstObject];\n\n// Example - remove the second person from the array\nPerson* secondPerson = [people popObjectAtIndex:1];\n\n// Example - remove the last person from the array\nPerson* lastPerson = [people popLastObject];\n```\n    \n## NSDictionary\n#### where:\n```objc\n- (NSDictionary*)where:(BOOL(^)(id key, id value))check;\n```\t\n_Uses the `check` block on every key-object in the dictionary to determine if they should be returned in the return array_\n\n```objc\n// Example - get all the keys and objects where the key is 3 or less characters\n\nNSDictionary* entriesWithKeysOf3OrLess = [peopleGroup where:^(id key, id value){ return [key length] \u003c= 3; }];\n```\n#### any:\n```objc\n- (BOOL)any:(BOOL(^)(id key, id value))check;\n```\t\n_Checks every key-object in the dictionary to see if any of the elements successfully pass the `check` block. If none pass, return `NO`, else `YES`._\n\n```objc\n// Exmaple - finds out if any of the keys are longer than 10 characters\n\nBOOL areAnyKeysLongerThan10 = [peopleGroups any:^(id key, id value){ return [key length] \u003e 10 }];\n```\n#### all:\n```objc\n- (BOOL)all:(BOOL(^)(id key, id value))check;\n```\n_Checks every key-object in the dictionary to see if all of the elements successfully pass the `check` block. If all elements pass, return `YES`, else `NO`._\n\n```objc\n// Exmaple - find out if all the keys are strings\n\nBOOL areKeysStrings = [peopleGroups all:^(id key, id value){ return [key class] == [NSString class] }];\n```\n## NSSet\n#### where:\n```objc\n- (NSSet*)where:(BOOL(^)(id obj))check;\n```\t\n_Uses the `check` block on every element in the set to determine if they should be returned in the return set_\n\n```objc\n// Example - find people that are 25 years old\n\nNSSet* 25YearOlds = [people where:^(id obj){ return [obj age] == 25; }];\n```\n#### any:\n```objc\n- (BOOL)any:(BOOL(^)(id obj))check;\n```\n_Checks every element in the set to see if any of the elements successfully pass the `check` block. If none pass, return `NO`, else `YES`._\n\n```objc\n// Example - check to see if anyone is under 18\n\nBOOL containsMinors = [people any:^(id obj){ return [obj age] \u003c 18; }];\n```\n#### all:\n```objc\n- (BOOL)all:(BOOL(^)(id obj))check;\n```\n_Checks every element in the set to see if all of the elements successfully pass the `check` block. If all elements pass, return `YES`, else `NO`._\n\n```objc\n// Example - check to see if everyone is 25 or over\n\nBOOL everyone25orOver = [people all:^(id obj){ return [obj age] \u003e= 25; }];\n```\n\n#### groupby:\n```objc\n- (NSDictionary*)groupBy:(id(^)(id obj))groupBlock;\n```\n_Uses the object returned from the `groupBlock` block as a key to group the object into a NSDictionary that contains a NSSet with all the objects that returned the same key_\n\n```objc\n// Example - group everyone by their last name\n\nNSDictionary* peopleByFamilyName = [people groupBy:^(id obj){ return [obj lastName]; }];\n```    \n#### select:\n```objc\n- (NSSet*)select:(id(^)(id originalObject))transform;\n```\t\n_Transforms elements in the set into another strongly type object that is returned from the `transform` block._\n\n```objc\n// Example - Change people objects into American Class objects\n\nNSSet* americans = [people select:^(id obj){ return [[American alloc] initWithFirstName:[obj firstName]\n\t\t\t\t\t\t\t\t\t       LastName:[obj lastName]\n\t\t\t\t\t\t\t\t\t\t    age:[obj age]] }];\n```                                                    \n#### selectKeypaths:\n```objc\n- (NSSet*)selectKeypaths:(NSString*)keypath, ... NS_REQUIRES_NIL_TERMINATION;\n```\n_Selects properties from the elements in the set using the keypath mechanism. Any number of keypaths maybe specified but the list must be `nil` terminated. The return value is an set of dictionaries. The dictionary contain the keypaths that were passed in as the parameters as the keys and the valueForKeyPath: as the values._\n\n```objc\n// Example - Get the four properties we need from the person object\n\nNSSet* americans = [people selectKeypaths:@\"firstName\",@\"lastName\",@\"parent.firstName\",@\"age\",nil];\n```\n------\n\nCreated by Adam Burkepile on 5/2/12.\n\nCopyright (C) 2012 Adam Burkepile.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facburk%2FSOCQ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facburk%2FSOCQ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facburk%2FSOCQ/lists"}