Skip to content

Instantly share code, notes, and snippets.

enum elseer<T> {
case `true`(T)
case `false`
func `else` (falseClosure: ()->(T)) -> T {
switch self {
case .true(let result):
return result
case .false:
@sidepelican
sidepelican / a.swift
Last active June 5, 2019 03:11
SwiftUI List rebuild test
import SwiftUI
struct User: Identifiable {
var id: Int
init(id: Int) {
self.id = id
}
}
import SwiftUI
struct MyNumber: View {
private let value: Int
init() {
print(#function, #line)
value = 1000
}
@sidepelican
sidepelican / ContentView.swift
Created June 10, 2019 22:49
BindableObjectのdidChangeは毎回同じものを返してね
import Combine
import SwiftUI
class MyPublisher<T, E>: Publisher where E: Error {
func receive<S>(subscriber: S) where S : Subscriber, Failure == S.Failure, Output == S.Input {
inner.receive(subscriber: subscriber)
Swift.print(#function, #line)
}
typealias Output = T
@sidepelican
sidepelican / combinationMask.swift
Created June 28, 2019 14:28
複数パスの図形を反転してマスク
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
}
@sidepelican
sidepelican / combinationMask.swift
Created June 28, 2019 14:28
複数パスの図形を反転してマスク
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
}
import Combine
import SwiftUI
struct IndexedCollection<Base: RandomAccessCollection>: RandomAccessCollection {
typealias Index = Base.Index
typealias Element = (index: Index, element: Base.Element)
let base: Base
var startIndex: Index { base.startIndex }
@sidepelican
sidepelican / TypeExtract.swift
Created September 17, 2019 14:04
雪だるま型パラから型を順番に取り出すやつ
import Foundation
protocol _View {
static var specialType: Any.Type { get }
}
protocol View: _View {
associatedtype Body: View
associatedtype Special
var body: Body { get }
import RxSwift
import RxCocoa
import UIKit
extension SharedSequence {
func assertStartWithEvent(file: StaticString = #file, line: UInt = #line) -> Self {
let deadline = Observable<Element>.create { observer -> Disposable in
fatalError("Event didn't come immediately after subscribe.", file: file, line: line)
}
.delaySubscription(.nanoseconds(0), scheduler: SharingStrategy.scheduler)
@sidepelican
sidepelican / main.rs
Created December 29, 2019 15:09
generics function overload
use std::marker::PhantomData;
struct T<A> {
_phantom: PhantomData<A>,
}
impl<U> T<&[U]> {
fn f(_: &[U]) {
println!("f(_: &[U])")
}