TOC
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
| // ---------------------------------------------------------------------------------------------------- | |
| // 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 | |
| // ---------------------------------------------------------------------------------------------------- |
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
| import UIKit | |
| import PlaygroundSupport | |
| import Foundation | |
| import CoreGraphics | |
| // ---------------------------------------------------------------------------------------------------- | |
| // MARK: - Interpolations | |
| // | |
| // http://elm4ward.github.io/swift/generator/protocol/2016/04/08/Interpolations.html | |
| // |
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
| // ---------------------------------------------------------------------------------------------------- | |
| // 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 |
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
| 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 |
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
| 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 |
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
| 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 |
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
| import UIKit | |
| enum GraphicsCommand { | |
| case setColour(colour: UInt32) | |
| case moveTo(x: Float, y: Float) | |
| case lineTo(x: Float, y: Float) | |
| } |
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
| import UIKit | |
| import PlaygroundSupport | |
| extension UIFont { | |
| static func font(for style: UIFontTextStyle, | |
| atScale scale: CGFloat = 1, | |
| usingFont fontInSize: ((CGFloat) -> UIFont)? = nil) -> UIFont { | |
| switch (fontInSize, scale) { |
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
| precedencegroup Apply { | |
| higherThan: ComparisonPrecedence | |
| associativity: right | |
| } | |
| precedencegroup Compose { | |
| higherThan: Apply | |
| } |