Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE
TypeOperators
, TemplateHaskell
#-}
module Tie where
import Prelude hiding ((.), id)
import Control.Category
import Data.Record.Label
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@tomlokhorst
tomlokhorst / MonadTest.cs
Created February 23, 2010 21:11
Monad type class ported to C#
// Monad type class ported to C#
// Only tested with: Mono C# compiler version 2.4.2.3
//
// The Monad type class has been split up into two .NET interface:
// - IMonad<A> has functions that can be applied _to_ monads (i.e. bind)
// - IMonadDictionary<A> has functions that _create_ monads (i.e. unit)
//
// Because .NET doesn't support higher kinded generics, we loose a bit of
// type safety. After calling `bind`, the return value has to be casted to
// the proper type.
@tomlokhorst
tomlokhorst / AppDelegate.swift
Created June 6, 2019 14:55
Xcode 11 iOS 12 crash: failed to demangle witness for associated type
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print(process(MyFoo()))
return true
}
/// - returns: `true` when dynamic type is `Equatable` and `==` returns `true`, otherwise `false`.
func areEquatablyEqual(_ lhs: Any, _ rhs: Any) -> Bool {
func receiveLHS<LHS>(_ typedLHS: LHS) -> Bool {
guard
let rhsAsLHS = rhs as? LHS
else { return false }
return areEquatablyEqual(typedLHS, rhsAsLHS)
}
return _openExistential(lhs, do: receiveLHS)
}
//
// DarwinNotificationCenter.swift
//
// Created by Nonstrict on 2023-12-07.
//
import Foundation
import Combine
private let center = CFNotificationCenterGetDarwinNotifyCenter()