Skip to content

Instantly share code, notes, and snippets.

@interface Tuple : NSObject
@property (readonly, nonatomic) id _1;
@property (readonly, nonatomic) id _2;
+ (id)tupleWithFirst:(id)_1 second:(id)_2;
- (id)initWithFirst:(id)_1 second:(id)_2;
@end
@akuraru
akuraru / gist:6618829
Last active December 23, 2015 09:59
Objective-Cでタプル
#define tuple(_1, _2) [Tuple tupleWithFirst:_1 second:_2];
@interface Tuple : NSObject
@property (readonly, nonatomic) id _1;
@property (readonly, nonatomic) id _2;
+ (id)tupleWithFirst:(id)_1 second:(id)_2;
- (id)initWithFirst:(id)_1 second:(id)_2;
@akuraru
akuraru / gist:5361253
Created April 11, 2013 06:44
[Objective-C]ランダムな長さのランダムな文字列を作る
- (NSString *)randStringWithMaxLenght:(NSInteger)max {
NSInteger length = [self randBetween:1 max:max];
unichar letter[length];
for (int i = 0; i < length; i++) {
letter[i] = [self randBetween:65 max:90];
}
return [[NSString alloc] initWithCharacters:letter length:length];
}
- (NSInteger)randBetween:(NSInteger)min max:(NSInteger)max {
return (random() % (max - min + 1)) + min;
@akuraru
akuraru / NSArray-Fanctional.h
Created October 10, 2012 12:03
Objective-Cで関数型プログラミングしたいなーと思ってやってみた。とりあえずFizzBuzz
#import <Foundation/Foundation.h>
typedef id (^fanc_t)(id);
typedef void (^noReturn_t)(id);
@interface NSArray (Fanctional)
+ (NSArray *)from:(NSInteger)from to:(NSInteger)to;
- (NSArray *)map:(fanc_t)fanc;