Browse Source

bug fixes, added ability to list package contents, added octotallylazy static libs and headers

Kevin Bradley 6 months ago
parent
commit
f953251a5c
50 changed files with 742 additions and 9 deletions
  1. 51 0
      bootstrapTool.xcodeproj/project.pbxproj
  2. 2 0
      bootstrapTool/Classes/InputPackage.h
  3. 7 3
      bootstrapTool/Classes/InputPackage.m
  4. 1 0
      bootstrapTool/Classes/StatusPackageModel.h
  5. 17 2
      bootstrapTool/Classes/StatusPackageModel.m
  6. 2 2
      bootstrapTool/Makefile
  7. 34 2
      bootstrapTool/main.m
  8. 32 0
      include/OCTotallyLazy/Callables.h
  9. 6 0
      include/OCTotallyLazy/EasyEnumerable.h
  10. 5 0
      include/OCTotallyLazy/EmptyEnumerator.h
  11. 5 0
      include/OCTotallyLazy/Enumerable.h
  12. 8 0
      include/OCTotallyLazy/EnumerateEnumerator.h
  13. 8 0
      include/OCTotallyLazy/FilterEnumerator.h
  14. 8 0
      include/OCTotallyLazy/FlattenEnumerator.h
  15. 4 0
      include/OCTotallyLazy/Flattenable.h
  16. 3 0
      include/OCTotallyLazy/Foldable.h
  17. 8 0
      include/OCTotallyLazy/Function1.h
  18. 11 0
      include/OCTotallyLazy/Function2.h
  19. 21 0
      include/OCTotallyLazy/Functions.h
  20. 11 0
      include/OCTotallyLazy/Group.h
  21. 7 0
      include/OCTotallyLazy/GroupedEnumerator.h
  22. 8 0
      include/OCTotallyLazy/MapEnumerator.h
  23. 3 0
      include/OCTotallyLazy/Mappable.h
  24. 19 0
      include/OCTotallyLazy/MemoisedEnumerator.h
  25. 8 0
      include/OCTotallyLazy/MemoisedSequence.h
  26. 7 0
      include/OCTotallyLazy/MergeEnumerator.h
  27. 59 0
      include/OCTotallyLazy/NSArray+OCTotallyLazy.h
  28. 16 0
      include/OCTotallyLazy/NSDictionary+OCTotallyLazy.h
  29. 16 0
      include/OCTotallyLazy/NSEnumerator+OCTotallyLazy.h
  30. 21 0
      include/OCTotallyLazy/NSSet+OCTotallyLazy.h
  31. 4 0
      include/OCTotallyLazy/NoSuchElementException.h
  32. 6 0
      include/OCTotallyLazy/None.h
  33. 59 0
      include/OCTotallyLazy/Numbers.h
  34. 3 0
      include/OCTotallyLazy/OCTotallyLazy-Prefix.pch
  35. 38 0
      include/OCTotallyLazy/OCTotallyLazy.h
  36. 26 0
      include/OCTotallyLazy/Option.h
  37. 13 0
      include/OCTotallyLazy/Pair.h
  38. 7 0
      include/OCTotallyLazy/PairEnumerator.h
  39. 8 0
      include/OCTotallyLazy/PartitionEnumerator.h
  40. 46 0
      include/OCTotallyLazy/Predicates.h
  41. 12 0
      include/OCTotallyLazy/Queue.h
  42. 12 0
      include/OCTotallyLazy/Range.h
  43. 9 0
      include/OCTotallyLazy/RepeatEnumerator.h
  44. 64 0
      include/OCTotallyLazy/Sequence.h
  45. 8 0
      include/OCTotallyLazy/SingleValueEnumerator.h
  46. 6 0
      include/OCTotallyLazy/Some.h
  47. 8 0
      include/OCTotallyLazy/TakeWhileEnumerator.h
  48. 5 0
      include/OCTotallyLazy/Types.h
  49. BIN
      ios/libOCTotallyStatic.a
  50. BIN
      lib/libOCTotallyStatic.a

+ 51 - 0
bootstrapTool.xcodeproj/project.pbxproj

@@ -19,6 +19,7 @@
 		4C56B59D29E670DD00D47844 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C56B59C29E670DD00D47844 /* main.m */; };
 		4C56B5A129E670F000D47844 /* Universalize.m in Sources */ = {isa = PBXBuildFile; fileRef = 32B2C837236BC8270085F065 /* Universalize.m */; };
 		4CADFF8C2AC0CD4C00218BB8 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CADFF8B2AC0CD4C00218BB8 /* main.m */; };
+		4CFFCC972AC6A61E0087F704 /* libOCTotallyStatic.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CFFCC952AC6A6110087F704 /* libOCTotallyStatic.a */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
@@ -49,6 +50,16 @@
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
+		4CFFCC3B2AC6A3790087F704 /* Embed Frameworks */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = "";
+			dstSubfolderSpec = 10;
+			files = (
+			);
+			name = "Embed Frameworks";
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
@@ -75,6 +86,7 @@
 		4C56B59C29E670DD00D47844 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
 		4CADFF892AC0CD4C00218BB8 /* chartest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = chartest; sourceTree = BUILT_PRODUCTS_DIR; };
 		4CADFF8B2AC0CD4C00218BB8 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+		4CFFCC952AC6A6110087F704 /* libOCTotallyStatic.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libOCTotallyStatic.a; path = lib/libOCTotallyStatic.a; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -82,6 +94,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				4CFFCC972AC6A61E0087F704 /* libOCTotallyStatic.a in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -109,6 +122,7 @@
 				4C56B59B29E670DD00D47844 /* univerisalize */,
 				4CADFF8A2AC0CD4C00218BB8 /* chartest */,
 				3249302820E4E29700E99767 /* Products */,
+				4CFFCC942AC6A6110087F704 /* Frameworks */,
 			);
 			sourceTree = "<group>";
 		};
@@ -171,6 +185,14 @@
 			path = chartest;
 			sourceTree = "<group>";
 		};
+		4CFFCC942AC6A6110087F704 /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+				4CFFCC952AC6A6110087F704 /* libOCTotallyStatic.a */,
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
@@ -181,6 +203,7 @@
 				3249302320E4E29700E99767 /* Sources */,
 				3249302420E4E29700E99767 /* Frameworks */,
 				3249302520E4E29700E99767 /* CopyFiles */,
+				4CFFCC3B2AC6A3790087F704 /* Embed Frameworks */,
 			);
 			buildRules = (
 			);
@@ -414,8 +437,18 @@
 				CODE_SIGN_STYLE = Automatic;
 				DEPLOYMENT_LOCATION = YES;
 				DEVELOPMENT_TEAM = "";
+				FRAMEWORK_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)",
+				);
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "$(SRCROOT)/bootstrapTool/Classes/Defines.h";
+				HEADER_SEARCH_PATHS = "$SRCROOT/include/**";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/lib",
+				);
+				OTHER_LDFLAGS = "-ObjC";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
@@ -427,8 +460,18 @@
 				CODE_SIGN_STYLE = Automatic;
 				DEPLOYMENT_LOCATION = YES;
 				DEVELOPMENT_TEAM = "";
+				FRAMEWORK_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)",
+				);
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "$(SRCROOT)/bootstrapTool/Classes/Defines.h";
+				HEADER_SEARCH_PATHS = "$SRCROOT/include/**";
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/lib",
+				);
+				OTHER_LDFLAGS = "-ObjC";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;
@@ -478,6 +521,10 @@
 				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
 				"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
 				CODE_SIGN_STYLE = Automatic;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/lib",
+				);
 				MACOSX_DEPLOYMENT_TARGET = 12.6;
 				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
 				MTL_FAST_MATH = YES;
@@ -495,6 +542,10 @@
 				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
 				"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
 				CODE_SIGN_STYLE = Automatic;
+				LIBRARY_SEARCH_PATHS = (
+					"$(inherited)",
+					"$(PROJECT_DIR)/lib",
+				);
 				MACOSX_DEPLOYMENT_TARGET = 12.6;
 				MTL_FAST_MATH = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";

+ 2 - 0
bootstrapTool/Classes/InputPackage.h

@@ -16,6 +16,8 @@
 @property (nonatomic, strong) NSString *appendedPrefix;
 @property (readwrite, assign) BOOL skipSignatureChecks;
 @property (readwrite, assign) BOOL forceOverwrite;
+@property (readwrite, assign) BOOL forceInstall;
+@property (readwrite, assign) BOOL unpack;
 @property (nonatomic, strong) NSString *validLDIDPath;
 @property (nonatomic, strong) NSString *arch; //if repackaging.
 @property (nonatomic, strong) NSString *excludeFile;

+ 7 - 3
bootstrapTool/Classes/InputPackage.m

@@ -75,7 +75,7 @@
     [self.files enumerateObjectsUsingBlock:^(InputPackageFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
         
         if ([obj.fileType isEqualToString:@"link"]){ //does this need to handle things differently?
-            [outFiles addObject:obj.path];
+            [outFiles addObject:obj.linkDestination];
         } else {
             [outFiles addObject:obj.path];
         }
@@ -194,7 +194,9 @@
             }
         } else if (safePackage.returnStatus == 2) //bail!!"
         {
-            return 2;
+            if (![self forceInstall]) {
+                return 2;
+            }
         }
     }
     
@@ -283,7 +285,9 @@
             
             //[controlFile replaceOccurrencesOfString:@"iphoneos-arm" withString:@"appletvos-arm64" options:NSLiteralSearch range:NSMakeRange(0, [controlFile length])];
             
-            [controlFile appendString:@"Status: install ok installed\n"];
+            NSString *controlString = self.unpack ? @"Status: install ok unpacked" : @"Status: install ok installed";
+            
+            [controlFile appendString:controlString];
             
             //DLog(@"control file: -%@-\n", controlFile);
             

+ 1 - 0
bootstrapTool/Classes/StatusPackageModel.h

@@ -27,6 +27,7 @@
 
 - (NSArray *)infoFiles;
 - (NSArray <InputPackageFile *>*)files;
+- (NSArray *)filesPlain;
 - (void)createPackage;
 - (instancetype)initWithRawControlString:(NSString *)controlString;
 

+ 17 - 2
bootstrapTool/Classes/StatusPackageModel.m

@@ -1,8 +1,17 @@
 
 #import "HelperClass.h"
+#import "OCTotallyLazy.h"
 
 @implementation StatusPackageModel
 
+
+- (NSArray *)filesPlain {
+    NSArray *files = [[self files] flatMap:^(InputPackageFile *item) {
+        return [item path];
+    }];
+    return files;
+}
+
 - (NSArray <InputPackageFile *>*)files {
     NSString *baseFile = [NSString stringWithFormat:@"%@.list", self.package];
     NSString *listFile = [self.bootstrapPath.relativeInfoFolderPath stringByAppendingPathComponent:baseFile];
@@ -33,8 +42,13 @@
 }
 
 - (NSString *)writeableControl {
-    NSMutableArray *controlArray = [[self.rawString componentsSeparatedByString:@"\n"] mutableCopy];
-    [controlArray removeLastObject];
+    NSArray *origArray = [self.rawString componentsSeparatedByString:@"\n"];
+    NSMutableArray *controlArray = [origArray mutableCopy];
+    [origArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        if ([obj containsString:@"Status:"]) {
+            [controlArray removeObject:obj];
+        }
+    }];
     [controlArray addObject:@"\n"];
     return [controlArray componentsJoinedByString:@"\n"];
 }
@@ -90,6 +104,7 @@
             NSString *output = [HelperClass singleLineReturnForProcess:command];
             DLog(@"output: %@", output);
         }
+        [FM removeItemAtPath:tmpFolder error:nil];
     }
 }
 

+ 2 - 2
bootstrapTool/Makefile

@@ -8,9 +8,9 @@ include $(THEOS)/makefiles/common.mk
 TOOL_NAME = bootstrapTool
 
 bootstrapTool_FILES = $(wildcard *.m) $(wildcard Classes/*.m)
-bootstrapTool_CFLAGS = -fobjc-arc -IClasses -include Classes/Defines.h
+bootstrapTool_CFLAGS = -fobjc-arc -IClasses -include Classes/Defines.h -I../include/OCTotallyLazy -I../include
 bootstrapTool_INSTALL_PATH = /fs/jb/usr/local/bin
-bootstrapTool_LDFLAGS = -framework Foundation
+bootstrapTool_LDFLAGS = -framework Foundation -lOCTotallyStatic -L../ios 
 bootstrapTool_CODESIGN_FLAGS=-Sent.xml
 
 include $(THEOS_MAKE_PATH)/tool.mk

+ 34 - 2
bootstrapTool/main.m

@@ -16,7 +16,7 @@
 #import <sys/utsname.h>
 #import "HelperClass.h"
 
-#define OPTION_FLAGS "o:i:ld:hcrbp:su:yn:a:Ce:"
+#define OPTION_FLAGS "o:i:ld:hcrbp:su:yn:a:Ce:fL:U"
 
 char *progname;
 char *path;
@@ -38,6 +38,9 @@ static struct option longopts[] = {
     { "arch",                      required_argument,      NULL,   'a' },
     { "create",                    no_argument,            NULL,   'C' },
     { "exclude",                   required_argument,      NULL,   'e' },
+    { "force",                     no_argument,            NULL,   'f' },
+    { "contents",                  required_argument,      NULL,   'L' },
+    { "unpack",                    no_argument,            NULL,   'U' },
     { NULL,                        0,                      NULL,    0  }
 };
 
@@ -59,7 +62,9 @@ void cmd_help(void){
     printf("  -p, --prefix\t\t\tthe prefix to append to all packages when repackaging or bumping a version number\n");
     printf("  -C, --create\t\t\tcreate a package from the bootstrap with an interactive list\n");
     printf("  -e, --exclude\t\t\tchoose a file list for excluded files when bumping, repackaging or creating a package\n");
-    
+    printf("  -f, --force\t\t\tforce an install operation, ignoring 'forbidden' roots\n");
+    printf("  -L, --contents\t\tlist the contents of an installed package, required a bootstrap path\n");
+    printf("  -U, --unpack\t\tmark the package as unpacked rather than installed in the status file\n");
     printf("\n");
 }
 
@@ -87,6 +92,9 @@ int main(int argc, char **argv) {
         BOOL forceYes = FALSE;
         BOOL new = FALSE;
         BOOL create = FALSE;
+        BOOL force = FALSE;
+        BOOL unpack = FALSE;
+        NSString *targetPkg = nil; //for --contents/L flag
         /*
         NSString *searchPathString = @"/Users/bradleyk/.rbenv/shims:/Users/bradleyk/Library/Python/3.9/bin:/Users/bradleyk/Library/Python/3.8/bin:/usr/local/lib/ruby/gems/3.0.0/bin:/usr/local/lib/ruby/gems/bin:/usr/local/opt/ruby/bin:/opt/local/bin:/opt/local/sbin:/Users/bradleyk/local/bin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/Users/bradleyk/Projects/goprojects/bin:/Users/bradleyk/Projects/theos/bin:/usr/local/bin/:/usr/local/bin:/bin/:/sbin/:/usr/sbin/";
         NSString *target = @"dpkg-deb";
@@ -107,6 +115,15 @@ int main(int argc, char **argv) {
         NSString *up = nil;
         while ((flag = getopt_long(argc, argv, OPTION_FLAGS, longopts, NULL)) != -1) {
             switch(flag) {
+                case 'f':
+                    force = TRUE;
+                    break;
+                case 'U':
+                    unpack = TRUE;
+                    break;
+                case 'L':
+                    targetPkg = [NSString stringWithUTF8String:optarg];
+                    break;
                 case 'o':
                     octalFile = [NSString stringWithUTF8String:optarg];
                     break;
@@ -189,6 +206,19 @@ int main(int argc, char **argv) {
             return 0;
         }
         
+        if (targetPkg) {
+            if (bootstrapPath) {
+                NSString *statusFile = [bootstrapPath relativeStatusFilePath];
+                NSArray *installedPackages = [HelperClass statusInstalledPackagesFromFile:statusFile bootstrapPath:bootstrapPath];
+                StatusPackageModel *filtered = [[installedPackages filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"package == %@", targetPkg]] firstObject];
+                DLog(@"found package: %@", filtered);
+                DLog(@"contents: %@", [filtered filesPlain]);
+            } else {
+                DLog(@"This option requires a bootstrap path!");
+            }
+            return 0;
+        }
+        
         if (bump == TRUE && debFile) {
             if (![FM fileExistsAtPath:debFile]){
                 DLog(@"%@ doesnt exist!, exiting...", debFile);
@@ -281,6 +311,8 @@ int main(int argc, char **argv) {
             InputPackage *output = [HelperClass packageForDeb:debFile];
             output.forceOverwrite = forceYes;
             output.excludeFile = excludeFile;
+            output.forceInstall = force;
+            output.unpack = unpack;
             return [output installToBootstrapPath:bootstrapPath];
             
         } else if (debFile) {

+ 32 - 0
include/OCTotallyLazy/Callables.h

@@ -0,0 +1,32 @@
+#import <Foundation/Foundation.h>
+
+typedef NSString *(^CALLABLE_TO_STRING)(id);
+typedef NSNumber *(^CALLABLE_TO_NUMBER)(id);
+typedef NSString *(^ACCUMULATOR_TO_STRING)(id, id);
+
+@interface Callables : NSObject
++ (id (^)(id))identity;
+
++ (NSString * (^)(NSString *))toUpperCase;
+
++ (NSString * (^)(NSString *, NSString *))appendString;
+
++ (ACCUMULATOR_TO_STRING)appendWithSeparator:(NSString *)separator;
+
++ (CALLABLE_TO_STRING)upperCase;
+
++ (CALLABLE_TO_NUMBER)increment;
+@end
+
+static CALLABLE_TO_STRING TL_upperCase() {
+    return [Callables upperCase];
+}
+
+static ACCUMULATOR_TO_STRING TL_appendWithSeparator(NSString *separator) {
+    return [Callables appendWithSeparator:separator];
+}
+
+static CALLABLE_TO_NUMBER TL_increment() {
+    return [Callables increment];
+}
+

+ 6 - 0
include/OCTotallyLazy/EasyEnumerable.h

@@ -0,0 +1,6 @@
+#import <Foundation/Foundation.h>
+#import "Enumerable.h"
+
+@interface EasyEnumerable : NSObject <Enumerable>
++ (EasyEnumerable *)with:(NSEnumerator * (^)())aConvertToEnumerator;
+@end

+ 5 - 0
include/OCTotallyLazy/EmptyEnumerator.h

@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+@interface EmptyEnumerator : NSEnumerator
++ (NSEnumerator *)emptyEnumerator;
+@end

+ 5 - 0
include/OCTotallyLazy/Enumerable.h

@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+@protocol Enumerable <NSObject>
+-(NSEnumerator *)toEnumerator;
+@end

+ 8 - 0
include/OCTotallyLazy/EnumerateEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+@interface EnumerateEnumerator : NSEnumerator
+- (EnumerateEnumerator *)initWithCallable:(id (^)(id))aCallableFunc seed:(id)aSeed;
+
++ (EnumerateEnumerator *)withCallable:(id (^)(id))callableFunc seed:(id)aSeed;
+
+@end

+ 8 - 0
include/OCTotallyLazy/FilterEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+
+@interface FilterEnumerator : NSEnumerator
+- (FilterEnumerator *)initWithEnumerator:(NSEnumerator *)anEnumerator andFilter:(BOOL (^)(id))aFunc;
+
++ (NSEnumerator *)withEnumerator:(NSEnumerator *)enumerator andFilter:(BOOL (^)(id))func;
+@end

+ 8 - 0
include/OCTotallyLazy/FlattenEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+
+@interface FlattenEnumerator : NSEnumerator
+- (FlattenEnumerator *)initWithEnumerator:(NSEnumerator *)anEnumerator;
+
++ (NSEnumerator *)withEnumerator:(NSEnumerator *)enumerator;
+@end

+ 4 - 0
include/OCTotallyLazy/Flattenable.h

@@ -0,0 +1,4 @@
+#import "Enumerable.h"
+@protocol Flattenable
+- (id)flatten;
+@end

+ 3 - 0
include/OCTotallyLazy/Foldable.h

@@ -0,0 +1,3 @@
+@protocol Foldable
+- (id)fold:(id)value with:(id (^)(id, id))functorBlock;
+@end

+ 8 - 0
include/OCTotallyLazy/Function1.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+#import "Types.h"
+
+@interface Function1 : NSObject
+
+- (id)initF1:(FUNCTION1)f1Block;
+-(id)apply:(id)argument1;
+@end

+ 11 - 0
include/OCTotallyLazy/Function2.h

@@ -0,0 +1,11 @@
+#import <Foundation/Foundation.h>
+#import "Types.h"
+#import "Function1.h"
+
+@interface Function2 : Function1
+
+- (id)initF2:(FUNCTION2)f2Block;
+
+- (Function1 *)apply:(id)argument1;
+
+@end

+ 21 - 0
include/OCTotallyLazy/Functions.h

@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+#import "Types.h"
+#import "Function2.h"
+
+
+@interface Functions : NSObject
++(Function2 *)f2:(FUNCTION2)f2Block;
+
++ (Function1 *)f1:(FUNCTION1)f1Block;
+
++ (Function1 *)compose:(Function1 *)a and:(Function1 *)b;
+
+@end
+
+static Function2 *f2(FUNCTION2 function2) {
+    return [Functions f2:function2];
+}
+
+static Function1 *f1(FUNCTION1 function1) {
+    return [Functions f1:function1];
+}

+ 11 - 0
include/OCTotallyLazy/Group.h

@@ -0,0 +1,11 @@
+#import <Foundation/Foundation.h>
+#import "Sequence.h"
+
+@interface Group : Sequence
+@property(nonatomic, strong) id <NSObject> key;
+
+- (Group *)initWithKey:(id)aKey enumerable:(id <Enumerable>)anEnumerable;
+
++ (Group *)group:(id)key enumerable:(id <Enumerable>)enumerable;
+
+@end

+ 7 - 0
include/OCTotallyLazy/GroupedEnumerator.h

@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+@interface GroupedEnumerator : NSEnumerator
+- (GroupedEnumerator *)initWithEnumerator:(NSEnumerator *)anEnumerator groupSize:(int)groupSize;
+
++ (GroupedEnumerator *)with:(NSEnumerator *)enumerator groupSize:(int)groupSize;
+@end

+ 8 - 0
include/OCTotallyLazy/MapEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+
+@interface MapEnumerator : NSEnumerator
+- (MapEnumerator *)initWithEnumerator:(NSEnumerator *)anEnumerator andFunction:(id (^)(id))aFunc;
+
++ (NSEnumerator *)withEnumerator:(NSEnumerator *)enumerator andFunction:(id (^)(id))func;
+@end

+ 3 - 0
include/OCTotallyLazy/Mappable.h

@@ -0,0 +1,3 @@
+@protocol Mappable
+- (id)map:(id (^)(id))funcBlock;
+@end

+ 19 - 0
include/OCTotallyLazy/MemoisedEnumerator.h

@@ -0,0 +1,19 @@
+#import <Foundation/Foundation.h>
+
+
+@interface MemoisedEnumerator : NSEnumerator
+-(int)previousIndex;
+-(int)nextIndex;
+-(id)previousObject;
+
+- (MemoisedEnumerator *)initWith:(NSEnumerator *)anEnumerator memory:(NSMutableArray *)aMemory;
+
+- (id)firstObject;
+
+- (void)reset;
+
++ (MemoisedEnumerator *)with:(NSEnumerator *)enumerator;
+
++ (MemoisedEnumerator *)with:(NSEnumerator *)enumerator memory:(NSMutableArray *)memory;
+
+@end

+ 8 - 0
include/OCTotallyLazy/MemoisedSequence.h

@@ -0,0 +1,8 @@
+#import "Sequence.h"
+
+@interface MemoisedSequence : Sequence
+@end
+
+static Sequence *memoiseSeq(id<Enumerable> underlying) {
+    return [MemoisedSequence with:underlying];
+}

+ 7 - 0
include/OCTotallyLazy/MergeEnumerator.h

@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+@interface MergeEnumerator : NSEnumerator
+- (MergeEnumerator *)initWith:(NSEnumerator *)leftEnumerator toMerge:(NSEnumerator *)rightEnumerator;
+
++(MergeEnumerator *)with:(NSEnumerator *)leftEnumerator toMerge:(NSEnumerator *)rightEnumerator;
+@end

+ 59 - 0
include/OCTotallyLazy/NSArray+OCTotallyLazy.h

@@ -0,0 +1,59 @@
+#import <Foundation/Foundation.h>
+#import "Option.h"
+#import "Mappable.h"
+#import "Flattenable.h"
+#import "Types.h"
+@class Sequence;
+@class Pair;
+
+@interface NSArray (OCTotallyLazy) <Mappable, Foldable, Enumerable, Flattenable>
+- (NSArray *)add:(id)value;
+- (NSArray *)cons:(id)value;
+- (NSArray *)drop:(int)toDrop;
+- (NSArray *)dropWhile:(PREDICATE)funcBlock;
+- (NSArray *)filter:(PREDICATE)filterBlock;
+- (Option *)find:(PREDICATE)filterBlock;
+- (NSArray *)flatMap:(FUNCTION1)functorBlock;
+- (NSArray *)flatten;
+- (id)fold:(id)value with:(id (^)(id accumulator, id item))functorBlock;
+- (void)foreach:(void (^)(id))funcBlock;
+- (BOOL)isEmpty;
+- (NSArray *)groupBy:(FUNCTION1)groupingBlock;
+- (NSArray *)grouped:(int)n;
+- (id)head;
+- (Option *)headOption;
+- (NSArray *)join:(id<Enumerable>)toJoin;
+- (id)mapWithIndex:(id (^)(id, NSInteger))funcBlock;
+- (Pair *)partition:(PREDICATE)toJoin;
+- (id)reduce:(id (^)(id, id))functorBlock;
+- (NSArray *)reverse;
+- (Pair *)splitAt:(int)splitIndex;
+- (Pair *)splitOn:(id)splitItem;
+- (Pair *)splitWhen:(PREDICATE)predicate;
+- (NSArray *)tail;
+- (NSArray *)take:(int)n;
+- (NSArray *)takeWhile:(PREDICATE)funcBlock;
+- (NSArray *)takeRight:(int)n;
+- (NSString *)toString;
+- (NSString *)toString:(NSString *)separator;
+- (NSString *)toString:(NSString *)start separator:(NSString *)separator end:(NSString *)end;
+- (NSArray *)zip:(NSArray *)otherSequence;
+- (NSArray *)zipWithIndex;
+
+- (Sequence *)asSequence;
+- (NSSet *)asSet;
+- (NSArray *)asArray;
+- (NSDictionary *)asDictionary;
+
+@end
+
+static NSArray *array(id items , ...) {
+    NSMutableArray *array = [NSMutableArray array];
+    va_list args;
+    va_start(args, items);
+    for (id arg = items; arg != nil; arg = va_arg(args, id)) {
+        [array addObject:arg];
+    }
+    va_end(args);
+    return array;
+}

+ 16 - 0
include/OCTotallyLazy/NSDictionary+OCTotallyLazy.h

@@ -0,0 +1,16 @@
+#import <Foundation/Foundation.h>
+#import "Option.h"
+#import "Sequence.h"
+
+@interface NSDictionary (Functional)
+-(NSDictionary *)filterKeys:(BOOL (^)(id))functorBlock;
+-(NSDictionary *)filterValues:(BOOL (^)(id))functorBlock;
+- (void)foreach:(void (^)(id, id))funcBlock;
+- (id)map:(NSArray * (^)(id, id))funcBlock;
+- (id)mapValues:(id (^)(id))funcBlock;
+-(Option *)optionForKey:(id)key;
+@end
+
+static NSDictionary *dictionary(Sequence * keys, Sequence * values) {
+    return [NSDictionary dictionaryWithObjects:[values asArray] forKeys:[keys asArray]];
+}

+ 16 - 0
include/OCTotallyLazy/NSEnumerator+OCTotallyLazy.h

@@ -0,0 +1,16 @@
+#import <Foundation/Foundation.h>
+#import "Option.h"
+#import "Predicates.h"
+
+@interface NSEnumerator (OCTotallyLazy)
+- (NSEnumerator *)drop:(int)toDrop;
+- (NSEnumerator *)dropWhile:(BOOL (^)(id))filterBlock;
+- (NSEnumerator *)filter:(BOOL (^)(id))filterBlock;
+- (NSEnumerator *)flatten;
+- (NSEnumerator *)map:(id (^)(id))func;
+
+- (NSEnumerator *)take:(int)n;
+- (NSEnumerator *)takeWhile:(BOOL (^)(id))predicate;
+- (Option *)find:(PREDICATE)predicate;
+
+@end

+ 21 - 0
include/OCTotallyLazy/NSSet+OCTotallyLazy.h

@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+#import "Some.h"
+#import "None.h"
+#import "Sequence.h"
+
+@interface NSSet (Functional) <Mappable, Foldable, Enumerable>
+- (Option *)find:(PREDICATE)filterBlock;
+- (NSSet *)filter:(PREDICATE)filterBlock;
+- (NSSet *)groupBy:(FUNCTION1)groupingBlock;
+- (id)head;
+- (Option *)headOption;
+- (NSSet *)join:(NSSet *)toJoin;
+- (id)reduce:(FUNCTION2)functorBlock;
+
+- (Sequence *)asSequence;
+- (NSArray *)asArray;
+@end
+
+static NSSet *set() {
+    return [NSSet set];
+}

+ 4 - 0
include/OCTotallyLazy/NoSuchElementException.h

@@ -0,0 +1,4 @@
+#import <Foundation/Foundation.h>
+
+@interface NoSuchElementException : NSException
+@end

+ 6 - 0
include/OCTotallyLazy/None.h

@@ -0,0 +1,6 @@
+#import <Foundation/Foundation.h>
+#import "Option.h"
+
+@interface None : Option
++ (Option *)none;
+@end

+ 59 - 0
include/OCTotallyLazy/Numbers.h

@@ -0,0 +1,59 @@
+#import "Types.h"
+
+@interface Numbers : NSObject
++ (FUNCTION2)min;
+
++ (FUNCTION2)max;
+
++ (FUNCTION2)sum;
+
++ (FUNCTION2)average;
+
++ (FUNCTION2)multiplyBy;
+
++ (FUNCTION1)multiplyBy:(NSNumber *)number;
+
++ (FUNCTION2)divideBy;
+
++ (FUNCTION1)divideBy:(NSNumber *)divisor;
+
++ (FUNCTION2)add;
+
++ (FUNCTION1)add:(NSNumber *)addition;
+
++ (FUNCTION2)subtract;
+
++ (FUNCTION1)substract:(NSNumber *)subtractor;
+@end
+
+static FUNCTION2 TL_max() {
+    return [Numbers max];
+}
+
+static FUNCTION2 TL_min() {
+    return [Numbers min];
+}
+
+static FUNCTION2 TL_sum() {
+    return [Numbers sum];
+}
+
+static FUNCTION2 TL_average() {
+    return [Numbers average];
+}
+
+static FUNCTION1 TL_multiplyBy(NSNumber *multiplier) {
+    return [Numbers multiplyBy:multiplier];
+}
+
+static FUNCTION1 TL_divideBy(NSNumber *divisor) {
+    return [Numbers divideBy:divisor];
+}
+
+static FUNCTION1 TL_add(NSNumber *addition) {
+    return [Numbers add:addition];
+}
+
+static FUNCTION1 TL_subtract(NSNumber *subtractor) {
+    return [Numbers substract:subtractor];
+}

+ 3 - 0
include/OCTotallyLazy/OCTotallyLazy-Prefix.pch

@@ -0,0 +1,3 @@
+#ifdef __OBJC__
+    #import <Foundation/Foundation.h>
+#endif

+ 38 - 0
include/OCTotallyLazy/OCTotallyLazy.h

@@ -0,0 +1,38 @@
+#import <OCTotallyLazy/Callables.h>
+#import <OCTotallyLazy/Enumerable.h>
+#import <OCTotallyLazy/Flattenable.h>
+#import <OCTotallyLazy/Functions.h>
+#import <OCTotallyLazy/Group.h>
+#import <OCTotallyLazy/Predicates.h>
+#import <OCTotallyLazy/Foldable.h>
+#import <OCTotallyLazy/Sequence.h>
+#import <OCTotallyLazy/Mappable.h>
+#import <OCTotallyLazy/None.h>
+#import <OCTotallyLazy/NoSuchElementException.h>
+#import <OCTotallyLazy/NSArray+OCTotallyLazy.h>
+#import <OCTotallyLazy/NSDictionary+OCTotallyLazy.h>
+#import <OCTotallyLazy/NSSet+OCTotallyLazy.h>
+#import <OCTotallyLazy/Numbers.h>
+#import <OCTotallyLazy/Option.h>
+#import <OCTotallyLazy/Pair.h>
+#import <OCTotallyLazy/Predicates.h>
+#import <OCTotallyLazy/Range.h>
+#import <OCTotallyLazy/Some.h>
+#import <OCTotallyLazy/Types.h>
+#import <OCTotallyLazy/EasyEnumerable.h>
+#import <OCTotallyLazy/EmptyEnumerator.h>
+#import <OCTotallyLazy/EnumerateEnumerator.h>
+#import <OCTotallyLazy/FilterEnumerator.h>
+#import <OCTotallyLazy/FlattenEnumerator.h>
+#import <OCTotallyLazy/RepeatEnumerator.h>
+#import <OCTotallyLazy/GroupedEnumerator.h>
+#import <OCTotallyLazy/MapEnumerator.h>
+#import <OCTotallyLazy/MemoisedEnumerator.h>
+#import <OCTotallyLazy/MemoisedSequence.h>
+#import <OCTotallyLazy/MergeEnumerator.h>
+#import <OCTotallyLazy/NSEnumerator+OCTotallyLazy.h>
+#import <OCTotallyLazy/PairEnumerator.h>
+#import <OCTotallyLazy/PartitionEnumerator.h>
+#import <OCTotallyLazy/Queue.h>
+#import <OCTotallyLazy/SingleValueEnumerator.h>
+#import <OCTotallyLazy/TakeWhileEnumerator.h>

+ 26 - 0
include/OCTotallyLazy/Option.h

@@ -0,0 +1,26 @@
+#import <Foundation/Foundation.h>
+#import "Mappable.h"
+#import "Foldable.h"
+#import "Enumerable.h"
+#import "Flattenable.h"
+@class Sequence;
+
+@interface Option : NSObject <NSCopying, Mappable, Foldable, Enumerable, Flattenable>
+-(BOOL)isEmpty;
+-(id)get;
+- (id)getSafely;
+-(id)getOrElse:(id)other;
+-(id)getOrInvoke:(id (^)())funcBlock;
+
+- (id)flatMap:(id (^)(id))funcBlock;
+
+-(Sequence *)asSequence;
+
+- (void)maybe:(void (^)(id))invokeWhenSomeBlock;
+
++(id)option:(id)value;
+@end
+
+static Option* option(id value) {
+    return [Option option:value];
+}

+ 13 - 0
include/OCTotallyLazy/Pair.h

@@ -0,0 +1,13 @@
+#import <Foundation/Foundation.h>
+#import "Sequence.h"
+
+@interface Pair : NSObject
+
+@property(nonatomic, readonly) id left;
+@property(nonatomic, readonly) id right;
+
+- (Pair *)initWithLeft:(id)aKey right:(id)aValue;
+- (Sequence *)toSequence;
++ (Pair *)left:(id)aLeft right:(id)aRight;
+
+@end

+ 7 - 0
include/OCTotallyLazy/PairEnumerator.h

@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+@interface PairEnumerator : NSEnumerator
+- (PairEnumerator *)initWithLeft:(NSEnumerator *)leftEnumerator right:(NSEnumerator *)rightEnumerator;
+
++(PairEnumerator *)withLeft:(NSEnumerator *)leftEnumerator right:(NSEnumerator *)rightEnumerator;
+@end

+ 8 - 0
include/OCTotallyLazy/PartitionEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+#import "Predicates.h"
+#import "Queue.h"
+
+@interface PartitionEnumerator : NSEnumerator
++ (PartitionEnumerator *)with:(NSEnumerator *)enumerator predicate:(PREDICATE)predicate matched:(Queue *)matched unmatched:(Queue *)unmatched;
+
+@end

+ 46 - 0
include/OCTotallyLazy/Predicates.h

@@ -0,0 +1,46 @@
+#import "Types.h"
+
+@interface Predicates : NSObject
++ (PREDICATE)alternate:(BOOL)startState;
+
++ (PREDICATE)andLeft:(PREDICATE)left withRight:(PREDICATE)right;
+
++ (PREDICATE)orLeft:(PREDICATE)left withRight:(PREDICATE)right;
+
++ (PREDICATE)countTo:(int)n;
+
++ (PREDICATE)containedIn:(NSArray *)existing;
+
++ (PREDICATE)containsString:(NSString *)toMatch;
+
++ (PREDICATE)equalTo:(id)comparable;
+
++ (PREDICATE)everyNth:(int)n;
+
++ (PREDICATE)greaterThan:(NSNumber *)comparable;
+
++ (PREDICATE)lessThan:(NSNumber *)comparable;
+
++ (PREDICATE)lessThanOrEqualTo:(NSNumber *)comparable;
+
++ (PREDICATE)not:(PREDICATE)predicate;
+
++ (PREDICATE)startsWith:(NSString *)prefix;
+
++ (PREDICATE)whileTrue:(PREDICATE)predicate;
+@end
+
+extern PREDICATE TL_alternate(BOOL startState);
+extern PREDICATE TL_and(PREDICATE left, PREDICATE right);
+extern PREDICATE TL_or(PREDICATE left, PREDICATE right);
+extern PREDICATE TL_countTo(int n);
+extern PREDICATE TL_containedIn(NSArray *existing);
+extern PREDICATE TL_containsString(NSString *toMatch);
+extern PREDICATE TL_equalTo(id comparable);
+extern PREDICATE TL_everyNth(int n);
+extern PREDICATE TL_greaterThan(NSNumber *comparable);
+extern PREDICATE TL_lessThan(NSNumber *comparable);
+extern PREDICATE TL_lessThanOrEqualTo(NSNumber *comparable);
+extern PREDICATE TL_not(PREDICATE predicate);
+extern PREDICATE TL_startsWith(NSString *prefix);
+extern PREDICATE TL_whileTrue(PREDICATE predicate);

+ 12 - 0
include/OCTotallyLazy/Queue.h

@@ -0,0 +1,12 @@
+#import <Foundation/Foundation.h>
+
+@interface Queue : NSObject
+- (BOOL)isEmpty;
+
+- (id)remove;
+
+- (void)add:(id)item;
+
++ (Queue *)queue;
+
+@end

+ 12 - 0
include/OCTotallyLazy/Range.h

@@ -0,0 +1,12 @@
+#import <Foundation/Foundation.h>
+#import "Sequence.h"
+#ifdef TL_SHORTHAND
+    #define range(num) [Range range:num]
+#endif
+
+@interface Range : NSObject
++ (Sequence *)range:(NSNumber *)start;
+
++ (Sequence *)range:(NSNumber *)start end:(NSNumber *)end;
+
+@end

+ 9 - 0
include/OCTotallyLazy/RepeatEnumerator.h

@@ -0,0 +1,9 @@
+#import <Foundation/Foundation.h>
+#import "MemoisedEnumerator.h"
+
+
+@interface RepeatEnumerator : NSEnumerator
+- (RepeatEnumerator *)initWith:(MemoisedEnumerator *)enumerator;
+
++ (RepeatEnumerator *)with:(MemoisedEnumerator *)anEnumerator;
+@end

+ 64 - 0
include/OCTotallyLazy/Sequence.h

@@ -0,0 +1,64 @@
+#import <Foundation/Foundation.h>
+#import "Types.h"
+#import "Mappable.h"
+#import "Option.h"
+#import "Enumerable.h"
+#import "NSArray+OCTotallyLazy.h"
+
+@interface Sequence : NSObject <NSFastEnumeration, Mappable, Enumerable>
+
+- (Sequence *)initWith:(id <Enumerable>)enumerator;
+- (Sequence *)add:(id)value;
+- (Sequence *)cons:(id)value;
+- (Sequence *)cycle;
+- (Sequence *)drop:(int)toDrop;
+- (Sequence *)dropWhile:(PREDICATE)funcBlock;
+- (Option *)find:(PREDICATE)predicate;
+- (id)first;
+- (Sequence *)flatMap:(FUNCTION1)funcBlock;
+- (id)filter:(PREDICATE)filterBlock;
+- (Sequence *)flatten;
+- (id)fold:(id)value with:(FUNCTION2)functorBlock;
+- (void)foreach:(void (^)(id))funcBlock;
+- (Sequence *)grouped:(int)n;
+- (Sequence *)groupBy:(FUNCTION1)groupingBlock;
+- (id)head;
+- (Option *)headOption;
+- (Sequence *)join:(id<Enumerable>)toJoin;
+- (Sequence *)mapWithIndex:(id (^)(id, NSInteger))func;
+- (Sequence *)merge:(Sequence *)toMerge;
+- (Pair *)partition:(PREDICATE)predicate;
+- (id)reduce:(id (^)(id, id))functorBlock;
+- (id)second;
+- (Pair *)splitAt:(int)splitIndex;
+- (Pair *)splitOn:(id)splitItem;
+- (Pair *)splitWhen:(PREDICATE)predicate;
+- (Sequence *)tail;
+- (Sequence *)take:(int)n;
+- (Sequence *)takeWhile:(PREDICATE)funcBlock;
+- (NSDictionary *)toDictionary:(id (^)(id))valueBlock;
+- (NSString *)toString;
+- (NSString *)toString:(NSString *)separator;
+- (NSString *)toString:(NSString *)start separator:(NSString *)separator end:(NSString *)end;
+- (Sequence *)zip:(Sequence *)otherSequence;
+- (Sequence *)zipWithIndex;
+
+- (NSArray *)asArray;
+- (NSSet *)asSet;
+- (NSDictionary *)asDictionary;
+
+
++ (Sequence *)with:(id <Enumerable>)enumerable;
+
+@end
+
+static Sequence *sequence(id items , ...) {
+    NSMutableArray *array = [NSMutableArray array];
+    va_list args;
+    va_start(args, items);
+    for (id arg = items; arg != nil; arg = va_arg(args, id)) {
+        [array addObject:arg];
+    }
+    va_end(args);
+    return [Sequence with:array];
+}

+ 8 - 0
include/OCTotallyLazy/SingleValueEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+
+@interface SingleValueEnumerator : NSEnumerator
+- (SingleValueEnumerator *)initWithValue:(id)aValue;
+
++ (id)singleValue:(id)value;
+@end

+ 6 - 0
include/OCTotallyLazy/Some.h

@@ -0,0 +1,6 @@
+#import <Foundation/Foundation.h>
+#import "Option.h"
+
+@interface Some : Option
++ (Option *)some:(id)value;
+@end

+ 8 - 0
include/OCTotallyLazy/TakeWhileEnumerator.h

@@ -0,0 +1,8 @@
+#import <Foundation/Foundation.h>
+
+
+@interface TakeWhileEnumerator : NSEnumerator
+- (NSEnumerator *)initWith:(NSEnumerator *)anEnumerator predicate:(PREDICATE)aPredicate;
+
++ (NSEnumerator *)with:(NSEnumerator *)anEnumerator predicate:(PREDICATE)predicate;
+@end

+ 5 - 0
include/OCTotallyLazy/Types.h

@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+typedef id(^FUNCTION1)(id);
+typedef id(^FUNCTION2)(id, id);
+typedef BOOL(^PREDICATE)(id);

BIN
ios/libOCTotallyStatic.a


BIN
lib/libOCTotallyStatic.a