Skip to content

Instantly share code, notes, and snippets.

class F<A> {
}
protocol Functor {
typealias A
typealias B
typealias FA = F<A>
typealias FB = F<B>
func fmap(a: FA, fn: (A -> B)) -> FB
}
Swift: Wanted: Generalized chaining
Summary:
Swift's Optional chaining is super cool.
It'd be really really cool if we could generalize that (monads!) to Haskell-like do-syntax.
Steps to Reproduce:
func renderForm(state: State) -> Element<State> {
let incButton = Button(title: "Increment", fn: { mapCount($0, inc) })
|> sizeToFit
|> offset(0, 40)
let decButton = Button(title: "Decrement", fn: { mapCount($0, dec) })
|> sizeToFit
let count = Label<State>(text: "\(state.count)")
|> sizeToFit
#!/bin/bash
echo "*** Removing saved user…"
rm -rf "${HOME}/Library/Application Support/GitHub for Mac/usersByServer.plist"
echo "*** Removing keychain items…"
security -q delete-internet-password -s github.com/mac
security -q delete-generic-password -l 'GitHub for Mac — github.com'
CGRect newFrame = [view.superview convertRect:view.frame toView:nil];
[view.window addSubview:view];
view.frame = newFrame;
CGRect newFrame = [newSuperview convertRect:view.frame fromView:nil];
[newSuperview addSubview:view];
view.frame = newFrame;
- (void)floatIntoWindow {
if(self.superview == self.window) return;
CGRect newFrame = [self.superview convertRect:self.frame toView:nil];
[self.window addSubview:self];
self.transform = [self transformForCurrentInterfaceOrientation];
self.frame = newFrame;
}
- (void)unfloatIntoView:(UIView *)newSuperview {
- (NSSize)sizeWithSize:(NSSize)size {
if([self length] < 1) return NSZeroSize;
NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize:size] autorelease];
NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithAttributedString:self] autorelease];
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease];
[layoutManager addTextContainer:textContainer];
[textStorage addLayoutManager:layoutManager];
[layoutManager setHyphenationFactor:0.0];
NSString *base64Encode(NSData *data);
NSString *base64Encode(NSData *data) {
BIO *context = BIO_new(BIO_s_mem());
BIO *command = BIO_new(BIO_f_base64());
context = BIO_push(command, context);
BIO_write(context, [data bytes], (int) [data length]);
(void) BIO_flush(context);
char *outputBuffer;
NSIndexSet *matches = [self.elements indexesOfObjectsWithOptions:NSEnumerationConcurrent
passingTest:(BOOL ^(ChiroXMLElement *element, NSUInteger index, BOOL *stop){
return (BOOL)([name compare:element.tag options:options] == NSOrderedSame);
})
];