Skip to content

Instantly share code, notes, and snippets.

@joemasilotti
joemasilotti / UI Testing - Mocking Network Data
Last active December 4, 2024 02:02
Xcode UI Testing - How to mock network data
.
@mbrandonw
mbrandonw / 1-Functor-and-Monad.md
Last active June 4, 2022 02:12
Swift Functor and Monad

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. However, it is very fragile (i.e. easy to crash the compiler).

For example, instance methods of fmap will run fine, but attempting to use a globally defined fmap that acts on Functor types will cause a crash. Similarly for bind. Unfortunately this means we cannot define the nice infix operator versions of these functions.

@tLewisII
tLewisII / Reader.swift
Created July 2, 2014 01:55
Try at a Reader Monad in Swift
//this is a playground
struct Reader<R,A> {
let f:R -> A
init(_ fun:R -> A) {
f = fun
}
static func wrap(val:A) -> Reader<R,A> {
return Reader({_ in val})