Skip to content

Instantly share code, notes, and snippets.

Jaden Geller JadenGeller

Block or report user

Report or block JadenGeller

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am JadenGeller on github.
  • I am jaden ( on keybase.
  • I have a public key whose fingerprint is CD7E 9E0B AE92 1CDB EBD9 3AFB 5989 E3D5 A174 FDD4

To claim this, I am signing this object:

View Swift Coalesce Function.swift
* coalesce takes in a list of optional values
* and returns the first one that is not nil
func coalesce<T>(all: @autoclosure () -> T? ...) -> T? {
for f: () -> T? in all {
if let x = f() { return x }
return nil
View Swift Unwrap Function.swift
* Returns the default value whenever the primary value is nil
* Otherwise returns the primary value
func unwrap<T>(primaryValue: T?, defaultValue: T) -> T {
if let value = primaryValue { return value }
else { return defaultValue }
// Examples
JadenGeller / Random Class.m
Last active Aug 29, 2015
Random Objective-C Class Returning Function
View Random Class.m
#import <objc/runtime.h>
Class randomClass(){
int numClasses = objc_getClassList(NULL, 0);
Class *classes = calloc(sizeof(Class), numClasses);
objc_getClassList(classes, numClasses);
Class randomClass = *(classes + arc4random_uniform(numClasses));
return randomClass;
View Swift Attempt Function.swift
* attempt takes a function that does not accept optional values
* and returns a new function that will work as usual with non-optional values
* and return nil when passed an optional value
func attempt<T,U>(f: T -> U)-> T? -> U? {
return { y in
if let x = y {
return f(x)
View Swift Offset Generator.swift
* Allows you to offset offset a generator
* and loop back around to the initial values
struct OffsetGenerator<G : GeneratorType> : GeneratorType {
var generator: G
var skipped = Array<G.Element>()
init(generator: G, var offset: Int){
self.generator = generator
JadenGeller / Lambda Wrapping.swift
Last active Aug 29, 2015
Lambda Wrapping to Guard Evaluation in Swift
View Lambda Wrapping.swift
// Imagine we have a function that curries
// That is, multiply takes in an integer a
// and returns a fuction that takes in another
// integer b that will return a * b
func multiply(a: Int) -> Int -> Int {
println("I got the first thing")
return { b in
println("I got the second thing")
return a * b
JadenGeller / Finite.swift
Last active Aug 29, 2015
Swift Finite Sequence
View Finite.swift
* Allows you to limit the count of a sequence
extension SequenceType {
func take(count: Int) -> FiniteSequence<Generator.Element> {
return FiniteSequence(backing: AnySequence(self), count: count)
View Swift Long Jump Wrapper.swift
// We will show how long jumps can be used within Swift
// Create jump and set it's position
let start = Jump()
setjmp(start.line) // Sets start's line to the current line
println("HI") // -> "Hi" -> "Hi" -> "Hi" -> ... (prints forever)
longjmp(start.line, 0) // Jumps back to start's line, e.g. setjmp(start.line)
View Swift Restart Skip Block.swift
// Let's start with an example
var c = 0
// Inside a jump block, calling the restart function starts over
// and calling the skip function exists the block
jump { restart, skip in
for i in 1...4 {
println("c: \(c); i: \(i)")
if c == 4 { skip() }
else if i == 3 { c++; restart() }
You can’t perform that action at this time.