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
-- Solving Fix / Mu / Nu exercise in | |
-- https://stackoverflow.com/questions/45580858/what-is-the-difference-between-fix-mu-and-nu-in-ed-kmetts-recursion-scheme-pac | |
{-# LANGUAGE RankNTypes, GADTs #-} | |
---------------------------------------- | |
-- Fix / Mu / Nu | |
newtype Fix f = Fix { unFix :: f (Fix f) } |
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
// https://stackoverflow.com/questions/53011500/how-to-replace-properties-using-mapped-types-in-typescript | |
// https://twitter.com/inamiy/status/1278511811025711104 | |
type ReplaceProps<T, From, To> = { | |
[K in keyof T]: K extends keyof From | |
? T[K] extends From[K] | |
? K extends keyof To | |
? To[K] | |
: T[K] | |
: T[K] |
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
// https://twitter.com/inamiy/status/1257538502226358272 | |
struct Hashable1: Hashable { | |
struct Hashable1a: Hashable {} | |
} | |
struct Hashable2: Hashable {} | |
Hashable1().hashValue | |
Hashable1.Hashable1a().hashValue | |
Hashable2().hashValue |
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
Just(()) | |
.delay(for: 1, scheduler: DispatchQueue.main) | |
.sink { | |
print("Q1. Can you hear me?") // Yes, even without retaining cancellable. Do you know why? :) | |
} | |
Just(()) | |
.delay(for: 1, scheduler: DispatchQueue.main) | |
.flatMap { Just(()) } | |
.sink { |
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
take 9 $ [0..] >>= flip replicateM [0, 1] | |
-- [[],[0],[1],[0,0],[0,1],[1,0],[1,1],[0,0,0],[0,0,1]] |
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
-- Data types a la carte | |
-- http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf | |
-- [Wadler's Blog: Data Types a la Carte](http://wadler.blogspot.com/2008/02/data-types-la-carte.html) | |
{-# LANGUAGE TypeOperators, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, ScopedTypeVariables #-} | |
---------------------------------------- | |
-- Expression Problem | |
---------------------------------------- |
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
fmap . fmap . fmap | |
:: (Functor f1, Functor f2, Functor f3) => | |
(a -> b) -> f1 (f2 (f3 a)) -> f1 (f2 (f3 b)) | |
fmap . fmap . fmap | |
== fmap . (fmap . fmap) | |
== fmap . (fmap fmap fmap) | |
== fmap fmap (fmap fmap fmap) | |
== (fmap fmap . fmap fmap) fmap | |
== fmap (fmap fmap) (fmap fmap) fmap |
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
// Private Conformance (Generic Manifesto) | |
// https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#private-conformances | |
// | |
// > Right now, a protocol conformance can be no less visible than the minimum of the conforming type's access and the protocol's access. | |
// > Therefore, a public type conforming to a public protocol must provide the conformance publicly. | |
// > The main problem with private conformances is the interaction with dynamic casting | |
public protocol PublicProtocol { | |
var foo: String { get } | |
} |
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
// Xcode 11.1 indent style | |
[1, 2, 3] | |
.filter { x in | |
x.isMultiple(of: 2) | |
} | |
.map { $0 } | |
.map { $0 } | |
[1, 2, 3] |
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
public protocol Transformer { | |
associatedtype To | |
associatedtype From | |
static func convert(to: To) throws -> From | |
static func convert(from: From) throws -> To | |
} | |
@propertyWrapper | |
public struct CustomCodable<T: Transformer> { | |
public var wrappedValue: T.To |