Skip to content

Instantly share code, notes, and snippets.

View bmeurer's full-sized avatar

Benedikt Meurer bmeurer

View GitHub Profile

Pattern Matching

This is a strawman proposal for adding pattern matching to ECMAScript. Pattern matching is useful for matching a value to some structure in a similar way to destructuring. The primary difference between destructuring and pattern matching are the use cases involved - destructuring is useful for binding pieces out of larger structures whereas pattern matching is useful for mapping a value's structure to data or a set of behaviors. In practice this means that destructuring tends to allow many shapes of data and will do its best to bind something out of it, whereas pattern matching will tend to be more conservative.

Additionally, the power of pattern matching is increased substantially when values are allowed to participate in the pattern matching semantics as a matcher as well as a matchee. This proposal includes the notion of a pattern matching protocol - a symbol method that can be implemented by objects that enables developers to use those values in pattern matching. A common scenario w

@bmeurer
bmeurer / UILabel+BMRoundedRectAdditions.h
Created June 13, 2011 15:05
Category on UILabel which adds a property showsRoundedRect, which, if set to YES, causes the label to be drawn on a rounded rect, similar to the emblem shown for the number of new mails in the iPhone Mail app.
/*-
* Copyright (c) 2011, Benedikt Meurer <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.