Skip to content

Instantly share code, notes, and snippets.

@jtbandes
Created June 7, 2010 22:02
Show Gist options
  • Save jtbandes/429252 to your computer and use it in GitHub Desktop.
Save jtbandes/429252 to your computer and use it in GitHub Desktop.
// replace annoying boilerplate with declarative justice using FunctionalKit:
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// =>
// nota bene: category on UITableView for convenient factory method is highly recommended.
id maybeCell = [[aTableView maybe] dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [maybeCell orJustFromBlock:^{ return [UITableViewCell cellWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; }];
@jonsterling
Copy link

I need to make a HOM for forcing operations to be lazy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment