This file contains 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
// | |
// DarwinNotificationCenter.swift | |
// | |
// Created by Nonstrict on 2023-12-07. | |
// | |
import Foundation | |
import Combine | |
private let center = CFNotificationCenterGetDarwinNotifyCenter() |
This file contains 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
/// - 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) | |
} |
This file contains 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 | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
print(process(MyFoo())) | |
return true | |
} |
This file contains 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
// 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. |
This file contains 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
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)? { |
This file contains 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
{-# LANGUAGE | |
TypeOperators | |
, TemplateHaskell | |
#-} | |
module Tie where | |
import Prelude hiding ((.), id) | |
import Control.Category | |
import Data.Record.Label |
This file contains 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
{-# LANGUAGE DoRec #-} | |
module ExprLang where | |
import Control.Monad.Error | |
import Data.List | |
import Data.Maybe | |
-- Language |
This file contains 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
// Read type class ported to C# | |
// Only tested with: Mono C# compiler version 2.4.2.3 | |
// | |
// Because there are no static interface members, new instances of the | |
// Dictionary classes have to be created (although they contain no state). | |
// | |
// The functions using the read method (like mulStrings) explicitly mention | |
// `int` in IReadDictionary<int>, but that's just like `x = read "4" :: Int` in | |
// Haskell. | |
// |
This file contains 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
// Functor type class ported to C# | |
// Only tested with: Mono C# compiler version 2.4.2.3 | |
// | |
// Because .NET doesn't support higher kinded generics, we can't exactly port | |
// the Functor type class. | |
// However, if we're willing to give up a bit of type safety, we can get the | |
// IFuctor interface to work. | |
// | |
// We only have to add a single type cast, directly after using fmap. E.g: | |
// var xs = new List<int>(); |
This file contains 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
// We can use Phantom Types to provide strongly typed acces to NSUserDefaults | |
// Similar to: http://www.objc.io/blog/2014/12/29/functional-snippet-13-phantom-types/ | |
// A key to UserDefaults has a name and phantom type | |
struct Key<T> { | |
let name: String | |
} | |
NewerOlder