This file contains hidden or 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
operator prefix ~ {} | |
@prefix func ~(pattern: String) -> NSRegularExpression! { | |
var error: NSError? | |
return NSRegularExpression.regularExpressionWithPattern( | |
pattern, | |
options: nil, | |
error: &error) | |
} |
This file contains hidden or 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
operator infix => { associativity left } | |
func => <K : Hashable, V>(key: K, value: V) -> (K, V) { | |
return (key, value) | |
} | |
let pairs: (String, Int)[] = [ | |
"e" => 10, | |
"t" => 7, | |
"i" => 2 | |
] |
This file contains hidden or 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
enum Quadrant { | |
case BottomLeft | |
case TopLeft | |
case BottomRight | |
case TopRight | |
static func forPoint(point: CGPoint) -> Quadrant { | |
switch (point.x, point.y) { | |
case (let x, let y) where x >= 0 && y >= 0: | |
return .TopRight |
This file contains hidden or 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
func chunk<T : Sliceable where T.Index : Strideable>( | |
s: T, | |
#from: T.Index, | |
#to: T.Index, | |
#by: T.Index.Stride | |
) -> GeneratorOf<T.SubSlice> { | |
var g = stride(from: from, to: to, by: by).generate() | |
return GeneratorOf<T.SubSlice> { | |
if let start = g.next() { |
This file contains hidden or 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/sh | |
test "$@" | |
RESULT=$? | |
if [[ $RESULT -eq 0 ]]; then | |
echo true | |
else | |
echo false | |
fi |
This file contains hidden or 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
export interface Meta<T> { | |
meta: T; | |
} | |
export type AnyType = string | symbol; | |
export interface Action<Type extends AnyType, Payload> { | |
type: Type; | |
payload: Payload; | |
error?: boolean; |
This file contains hidden or 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
namespace TypeBranding { | |
// This incurs no runtime cost. It is a purely compile-time construct. | |
type Meters = number & { __metersBrand: any }; | |
type Miles = number & { __milesBrand: any }; | |
function Meters(i: number): Meters { return i as Meters; } | |
function Miles(i: number): Miles { return i as Miles; } | |
let a: Meters; |
This file contains hidden or 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
export enum Event1 { | |
SIGN_IN_WALL = 'Sign In Wall' as any, | |
SIGN_UP = 'Sign Up' as any, | |
} | |
{ | |
const x = Event1.SIGN_UP; // type = Event1 | |
const y: number = x; | |
// Verdict: approach is succint, but incorrectly allows type widening to number. | |
} |
This file contains hidden or 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
var _ I = S{} |
This file contains hidden or 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 Narrow { | |
x: number; | |
y: number; | |
} | |
interface Wide extends Narrow { | |
z: number; | |
} |