Skip to content

Instantly share code, notes, and snippets.

View andersio's full-sized avatar

Anders Ha andersio

View GitHub Profile
import XCTest
import ReactiveSwift
import Result
class PerformanceTests: XCTestCase {
let iterations = 50_000
func testStackBlowing() {
func nest(_ signal: Signal<(), NoError>) -> Signal<(), NoError> {
let (never, o) = type(of: signal).pipe()
import XCTest
import ReactiveSwift
import Result
class Test: XCTestCase {
func testPerformanceExample() {
let (signal, observer) = Signal<Int, NoError>.pipe()
let transformed = signal
@testable import ReactiveSwift
import XCTest
class AtomicTests: XCTestCase {
let iterations = 10000000
func test() {
var info = mach_timebase_info()
mach_timebase_info(&info)
let info = mach_timebase_info_t.allocate(capacity: 1)
mach_timebase_info(info)
var avg: Double = 0
let lock: UnsafeMutableRawPointer!
if #available(macOS 10.12, iOS 10.0, *), true {
let lock1 = os_unfair_lock_t.allocate(capacity: 1)
lock1.initialize(to: os_unfair_lock())
lock = UnsafeMutableRawPointer(lock1)
// Assuming we have this state:
courseId
// Assuming we have these view related stuff:
refreshButton
courseCodeLabel
courseTitleLabel
sectionsAdapter // ArrayAdapter
sectionSpinner

Mutable Validating Property

final class ViewModel {
	enum Error {
		case usernameNonAlphanumeric
		case usernameMismatch
	}

	// Normal validation
	let username = ValidatingProperty<String, Error>("") { input, error in
let username = MutableProperty("")
let mutableView = username
.validate { $0.characters.count >= 3 ? .success() : .failure(FormError("At least three characters.")) }
.validate { !$0.characters.contains("@") ? .success() : .failure(FormError("Contains invalid characters.")) }
.map(forward: { $0.isEmpty ? "" : "\($0)@reactiveswift" },
attemptBackward: { Result($0.stripSuffix("@reactiveswift"), failWith: FormError("Missing `@reactiveswift` suffix.")) })
mutableView.validations.observeValues { print("error: \($0.error?.reason ?? "NoError")") }
/*:
> # IMPORTANT: To use `ReactiveSwift.playground`, please:
1. Retrieve the project dependencies using one of the following terminal commands from the ReactiveSwift project root directory:
- `git submodule update --init`
**OR**, if you have [Carthage](https://github.com/Carthage/Carthage) installed
- `carthage checkout --no-use-binaries`
1. Open `ReactiveSwift.xcworkspace`
1. Build `Result-Mac` scheme
1. Build `ReactiveSwift-macOS` scheme
/*:
> # IMPORTANT: To use `ReactiveSwift.playground`, please:
1. Retrieve the project dependencies using one of the following terminal commands from the ReactiveSwift project root directory:
- `git submodule update --init`
**OR**, if you have [Carthage](https://github.com/Carthage/Carthage) installed
- `carthage checkout --no-use-binaries`
1. Open `ReactiveSwift.xcworkspace`
1. Build `Result-Mac` scheme
1. Build `ReactiveSwift-macOS` scheme
infix operator <~
//func <~<T: Target, S: Source>(left: T, right: S) {
// print("Free Function")
//}
//func <~<S: Source>(left: BindingTarget, right: S) {
// print("Free Function 2")
//}