This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code from “Functional Programming in Java, Chapter 7”. | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
import java.math.BigInteger; | |
@FunctionalInterface | |
interface TailCall<T> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Maybe a functional category on NSArray will help. | |
@interface NSArray(Extension) | |
-(NSArray*) map:(id(^)(id object))block; | |
@end | |
@implementation NSArray(Extension) | |
-(NSArray*) map:(id(^)(id object))block { | |
NSParameterAssert(block != NULL); | |
NSMutableArray *results = [[NSMutableArray alloc] initWithCapacity:[self count]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
typedef NS_ENUM(unsigned char, MyTreeVisitingOrder) { | |
MyTreeOrderDepthFirst, | |
MyTreeOrderValueFirst | |
}; | |
#define Tree NSObject<MyTree> | |
@protocol MyTree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface Animal : NSObject | |
{ | |
NSObject *iProtected; | |
@package | |
NSObject *iPackage; | |
@private | |
NSObject *iPrivate; | |
@protected | |
NSObject *iProtected2; // default access. Only visible to subclasses. | |
@public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -framework Foundation main.m -o main && ./main | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSUInteger (^__block factorial)(NSUInteger n); | |
NSUInteger (^__block __weak weakFactorial)(NSUInteger n); | |
weakFactorial = factorial = ^ NSUInteger (NSUInteger n) { | |
return n==0 ? 1 : n * weakFactorial(n-1); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#include <stdlib.h> | |
#include <objc/runtime.h> | |
@interface A : NSObject | |
@property (assign) int meaning; | |
@end | |
@implementation A | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <objc/runtime.h> | |
#import <Foundation/Foundation.h> | |
@interface Hi : NSObject | |
@end | |
@implementation Hi { | |
NSString *something; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script builds the iOS and Mac openSSL libraries | |
# It's expanded from https://github.com/st3fan/ios-openssl | |
set -xe | |
# Setup paths to stuff we need | |
OPENSSL_VERSION="1.0.1e" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSTimer (BlockSupport) | |
+ (NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)interval | |
block:(void(^)())block | |
repeats:(BOOL)repeats; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#undef X | |
typedef void (^salute_t)(); | |
@interface Person : NSObject | |
@property (nonatomic,copy) NSString *name; | |
@property (nonatomic,copy) salute_t salute; |