Skip to content

Instantly share code, notes, and snippets.

View elm4ward's full-sized avatar

Elmar Kretzer elm4ward

View GitHub Profile
import Foundation
// ---------------------
// Actions
// ---------------------
typealias Closure<S> = (inout S) -> Void
/// Our Actions are basically a Tree of Nodes
/// Data for multiple args
import Foundation
// contramap
precedencegroup I3 { associativity: left higherThan: LogicalConjunctionPrecedence }
precedencegroup I4 { associativity: left higherThan: LogicalConjunctionPrecedence, I3 }
infix operator <!> : I4
let flag: (Bool) -> String = { $0 ? "✅" : "❌" }
let flag: (Bool) -> String = { $0 ? "✅" : "❌" }
// ------------------------
// Predicative
// ------------------------
protocol Predicative {
static func + (lhs: Self, rhs: Self) -> Self
static func * (lhs: Self, rhs: Self) -> Self
static func gt<P: PredicateLike>(_: P.Input) -> P where P.Input: Comparable, P.Output == Self
@elm4ward
elm4ward / AnimationsAsSemiring.swift
Created November 15, 2017 18:31
Animations As Semiring
import Foundation
import UIKit
import PlaygroundSupport
// --------------------------------------------------------------------------------
// MARK: - operators
// --------------------------------------------------------------------------------
precedencegroup MonoidComposePrecedence {
associativity: left higherThan: AssignmentPrecedence lowerThan: AdditionPrecedence
@elm4ward
elm4ward / Traced-Cowriter.swift
Last active November 15, 2018 20:39
Searching for a Traced (Cowriter) usecase ...
// --------------------------------------------------------------------------------
// MARK: - Operators
// --------------------------------------------------------------------------------
precedencegroup Cobind { associativity: left }
precedencegroup Cokleisli {
associativity: left
higherThan: Cobind
@elm4ward
elm4ward / Bijection.swift
Last active October 23, 2023 20:30
Something Bijection
// --------------------------------------------------------------------------------
// MARK: - Prerequsites
// --------------------------------------------------------------------------------
/// Compose Operator
precedencegroup BijectionGroup { associativity: left }
infix operator <> : BijectionGroup
/// Typealias for a binary function
typealias Bin<T> = (T) -> (T) -> T
// ------------------------------------
// Network
// ------------------------------------
struct MeetupResponse {
var groupName: String = ""
var groupOrganizers: [String] = []
var meetupTitle: String = ""
var meetupAttendes: Int = 0
@elm4ward
elm4ward / ProofofProducts.swift
Last active April 25, 2017 13:28
Proofing Products / Tuples ...
precedencegroup Apply {
higherThan: ComparisonPrecedence
associativity: right
}
precedencegroup Compose {
higherThan: Apply
}
@elm4ward
elm4ward / font.swift
Created March 1, 2017 08:08
Using iOS FontStyles with different weights and scales
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) {
@elm4ward
elm4ward / dsltest.swift
Last active September 1, 2016 10:47 — forked from marcpalmer/dsltest.swift
Example of using Swift property change observation to bind models to arguments passed to DSL closures
import UIKit
enum GraphicsCommand {
case setColour(colour: UInt32)
case moveTo(x: Float, y: Float)
case lineTo(x: Float, y: Float)
}