Skip to content

Instantly share code, notes, and snippets.

import Foundation
func invocation<C: AnyObject, In, Out>
(target target: C, method: C -> In -> Out)
-> In -> Out?
{
return {
[weak target] input in
if let target = target {
return method(target)(input)
@Vadim-Yelagin
Vadim-Yelagin / BinarySearch.swift
Created November 12, 2015 14:37
Binary search extension for CollectionType in Swift
extension CollectionType where Index: RandomAccessIndexType {
/// Finds such index N that predicate is true for all elements up to
/// but not including the index N, and is false for all elements
/// starting with index N.
/// Behavior is undefined if there is no such N.
func binarySearch(predicate: Generator.Element -> Bool) -> Index {
var low = startIndex
var high = endIndex
while low != high {
func animatingContext(duration: TimeInterval) -> ((@escaping (Void) -> Void) -> Void) {
return { UIView.animate(withDuration: duration, animations: $0) }
}
public extension SignalProtocol {
public func observe(context: @escaping (@escaping (Void) -> Void) -> Void) -> Signal<Value, Error> {
return Signal { observer in
return self.observe { event in
switch event {
case .value: