Skip to content

Instantly share code, notes, and snippets.

@natecook1000
natecook1000 / SwiftCoRoutine.swift
Created March 15, 2017 16:04 — forked from mzaks/SwiftCoRoutine.swift
A simple coroutine for swift
import Foundation
public class CoRoutine<T> {
private var index = 0
private var sequence : [T]
private var routine : (T)->()
private let step : Int?
private let deltaTime : TimeInterval?
private(set) public var isCanceled : Bool = false
private(set) public var isDone : Bool = false
@natecook1000
natecook1000 / joke.swift
Last active October 22, 2017 16:00 — forked from airspeedswift/joke.swift
Multiline Literals
func tellJoke(name: String, character: Character) {
let punchline = String(name.filter { $0 != character })
let n = name.count - punchline.count
let joke = """
Q: Why does \(name) have \(n) \(character)'s in their name?
A: I don't know, why does \(name) have \(n) \(character)'s in their name?
Q: Because otherwise they'd be called \(punchline).
"""
print(joke)
let xs = [0,1,2,3,4,5]
let double: (Int) -> Int = { $0 * 2 }
let isEven: (Int) -> Bool = { $0 % 2 == 0 }
// Goal: [0,2,4,6,4,10]. Double all but the last even element.
extension Collection {
func mapExceptLast(matching predicate: (Element) -> Bool, transform: (Element) -> Element) -> [Element] {
var result: [Element] = []