This file contains hidden or 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 kotlin.math.abs | |
fun solve(input: String): Int { | |
val firstList: MutableList<Int> = mutableListOf() | |
val secondList: MutableList<Int> = mutableListOf() | |
var result = 0 | |
for (line in input.lines()) { | |
val components = line.split(" ").filter { it != "" }.map { it.toInt() } | |
firstList.add(components[0]) |
This file contains hidden or 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
// Copy and Paste this in your project | |
import Combine | |
import Foundation | |
extension Publishers { | |
struct PublisherObserver<V, E: Swift.Error> { | |
private let sendValue: (V) -> Void | |
private let sendCompletion: (Subscribers.Completion<E>) -> Void | |
init( |
This file contains hidden or 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 | |
public final class EventStream<Element> { | |
private(set) var handlers: [StreamSubscription: StreamHandler<Element>] = [:] | |
private var eventsQueue: [Event<Element>] = [] | |
private var isEnabled: Bool = true | |
private init() {} | |
public static func create(_ handler: @escaping (StreamHandler<Element>) -> Void) -> EventStream<Element> { |
This file contains hidden or 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
// | |
// AsyncOperation.swift | |
// SwiftUIPoC | |
// | |
// Created by Fernando Martín Ortiz on 25/10/2020. | |
// | |
import Combine | |
protocol AsyncOperation { |
This file contains hidden or 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 SwiftUI | |
import Combine | |
struct CreateToDoScreen: View { | |
@StateObject var viewModel = CreateToDoViewModel() | |
var body: some View { | |
VStack { | |
TextField("Title", text: $viewModel.title) | |
Toggle("Completed", isOn: $viewModel.completed) |
This file contains hidden or 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 | |
precedencegroup MutationPrecedence { | |
associativity: left | |
} | |
infix operator +> : MutationPrecedence | |
func +> <A> (v: A, f: (inout A) -> Void) -> A { | |
var copy = v |
This file contains hidden or 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 | |
enum NetworkError: Error { | |
case generic | |
} | |
precedencegroup PipeAssociativity { | |
associativity: left | |
} |
This file contains hidden or 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 | |
struct Promise<T> { | |
typealias ResultType = Result<T, Error> | |
typealias ResultObserver = (ResultType) -> Void | |
typealias CreatorFunction = (@escaping ResultObserver) -> Void | |
private let creatorFunction: CreatorFunction | |
init(creatorFunction: @escaping CreatorFunction) { | |
self.creatorFunction = creatorFunction |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
</head> | |
<!-- | |
Dumber Gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. |
This file contains hidden or 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 create a protocol for formatting a name | |
protocol NameFormatterType { | |
func format(name: String) -> String | |
} | |
// A concrete implementation adds a prefix "Sir" to the given name. | |
struct SirFormatter: NameFormatterType { | |
func format(name: String) -> String { | |
"Sir \(name)" | |
} |
NewerOlder