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
let urlRequest = URLRequest(url: URL(string: "https://my.api.com")!) | |
// Option 1: Typealias to closure | |
typealias URLRequester1 = (URLRequest) -> AnyPublisher<(data: Data, response: URLResponse), URLError> | |
enum URLRequesterNamespace { | |
static var prod: URLRequester1 = { req in URLSession.shared.dataTaskPublisher(for: req).eraseToAnyPublisher() } | |
static func mock(alwaysReturns: (data: Data, response: URLResponse)) -> URLRequester1 { | |
return { _ in |
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 Combine | |
public enum APIError: Error { | |
case urlError(URLError) | |
case invalidResponse(URLResponse) | |
case decodingError(DecodingError) | |
case unknownError(Error) | |
} | |
extension Publisher where Output == (data: Data, response: URLResponse), Failure == URLError { | |
public func decode<T: Decodable, Decoder: TopLevelDecoder>(type: T.Type, decoder: Decoder) -> AnyPublisher<T, APIError> |
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 Foundation | |
import SwiftUI | |
// As pointed by @pointfreeco (no pun intended) here https://twitter.com/pointfreeco/status/1285209505714843648 | |
// these types can't be called Profunctor as they are covariant and contravariant on the very same element (single | |
// generic parameter, instead of 2). That way, function "dimap" here is academically incorrect and either contramap | |
// or pullback should be used, instead. | |
struct Endo<Value> { | |
let run: (Value) -> Value |
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 Combine | |
import Foundation | |
import PlaygroundSupport | |
struct Reader<E, A> { | |
let run: (E) -> A | |
func map<B>(_ fn: @escaping (A) -> B) -> Reader<E, B> { | |
Reader<E, B> { e in | |
fn(self.run(e)) | |
} |
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 Foundation | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
struct Promise<A> { | |
let subscribe: (@escaping (A) -> Void) -> Void | |
} | |
extension Promise { | |
func map<B>(_ f: @escaping (A) -> B) -> Promise<B> { |
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
#ifndef Limit_hpp | |
#define Limit_hpp | |
#include "Linq.hpp" | |
template<typename T> | |
class Limit { | |
private: | |
unsigned long limit = 0; |