Skip to content

Instantly share code, notes, and snippets.

View elm4ward's full-sized avatar

Elmar Kretzer elm4ward

View GitHub Profile
import Foundation
let mark = Array(repeating: "-", count: 40).joined(separator: "")
func chapter(s: String, line: Int = #line) { print("\n", "// " + mark, "// \(s) - line: \(line)", "// " + mark, separator: "\n")}
func section(s: String, line: Int = #line) { print("", "~~ \(s)", separator: "\n")}
func assertEqual<A: Equatable>(_ a: A, _ b: A) { assert(a == b); print(a, "==", b) }
// ----------------------------------------------------------------------------------------------
// It`s a generic type of world
//
// http://elm4ward.github.io/swift/generics/mocking/dependency/injection/2016/05/21/generic-dependency-mocking.html
let mark = Array(repeating: "-", count: 40).joined(separator: "")
func chapter(_ s: String, line: Int = #line) { print("\n", "// " + mark, "// \(s) - line: \(line)", "// " + mark, separator: "\n")}
func section(_ s: String, line: Int = #line) { print("\n", "# \(s)", mark, separator: "\n")}
import struct CoreGraphics.CGFloat
// ----------------------------------------------------------------------------------------------------
// MARK: - Bi-directional Type Inference
//
// http://elm4ward.github.io/swift/generics/type/inference/2016/05/01/bidirectional.html
let mark = "####################################"
let chapter: (String) -> Void = { print("\n", mark, "# \($0)", mark, separator: "\n")}
// ----------------------------------------------------------------------------------------------------
// MARK: - Look ma, no protocols
//
// http://elm4ward.github.io/swift/generics/type/erasure/2016/04/21/erase-em-all.html
//
// Erasing generics to life in freedom
// This is a follow up to the article about Protocols with Typealias
// ----------------------------------------------------------------------------------------------------
// Iterators for Naysayer
//
// Generating understandable, reusable, simplified, ... code with Iterators
//
// http://elm4ward.github.io/swift/Iterator/protocol/2016/04/14/Iterators-for-the-naysayers.html
//
// 1. Base Protocols
// 2. ZipWithSum
// 3. ZipWithSumFrom
import UIKit
import PlaygroundSupport
import Foundation
import CoreGraphics
// ----------------------------------------------------------------------------------------------------
// MARK: - Interpolations
//
// http://elm4ward.github.io/swift/generator/protocol/2016/04/08/Interpolations.html
//
// ----------------------------------------------------------------------------------------------------
// MARK: - Lazy comonadic array zipper
//
// http://elm4ward.github.io/swift/functional/comonad/2016/04/06/da-lazy-one.html
//
// Stacking functions lazily can speed up your code.
//
// 1. The struct
// 2. Lazy in action
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Protocol Flow in Swift
//
// http://elm4ward.github.io/swift/protocols/2016/04/02/protocollisions.html
//
// 1. The Protocols
// 2. The Flow
// 3. String Example
// 4. Custom Example
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// ArrayZipper Comonads in Swift
//
// http://elm4ward.github.io/swift/functional/comonad/2016/03/30/monads-comonads.html
//
// 1. Array extensions
// 2. ArrayZipperError
// 3. ArrayZipper
// 4. ArrayZipper extensions
// 5. custom operators
/// the protocol
protocol ImplicitDefault {
static var implicitDefault: Self { get }
}
/// the implementation for Strings
extension String: ImplicitDefault {
/// i dont care i take the empty string as default