Skip to content

Instantly share code, notes, and snippets.

View LucianoPAlmeida's full-sized avatar
💭
Daniel 11:32

Luciano Almeida LucianoPAlmeida

💭
Daniel 11:32
View GitHub Profile
@LucianoPAlmeida
LucianoPAlmeida / KeyPath.swift
Last active April 24, 2020 00:35
KeyPath<Root, Value> example
struct Player: CustomDebugStringConvertible {
var number: Int
var name: String
var debugDescription: String { "Player {number=\(number), name= \(name)}" }
}
func keyPaths<R, T>(_ base: R, kp: KeyPath<R, T>) {
let value = base[keyPath: kp]
print("kp value: \(value)")
struct S1 {
private var _buffer: [UInt8] = []
var values: [UInt8] {
get { _buffer }
_modify {
yield &_buffer
}
#include <iostream>
#include <vector>
template <typename T>
T adder(T t) {
return t;
}
template <typename T, typename ... Args>
import Quick
import Nimble
@testable import FormulaOne
class TestPitStop: QuickSpec {
var car: Car?
var service: CarService = CarService()
@LucianoPAlmeida
LucianoPAlmeida / quick-nimble-sync.swift
Last active July 27, 2019 16:26
Quick and Nimble Testing
import Quick
import Nimble
@testable import FormulaOne
class TestPitStop: QuickSpec {
var car: Car?
var service: CarService = CarService()
fun getUser(usid: String) {
apiToken { // it: String
findUser(usid: it) { //it: User
// Do what you want with the user.
}
}
}
@LucianoPAlmeida
LucianoPAlmeida / yield-coroutines.kt
Last active July 20, 2019 20:57
Kotlin coroutines
fun hi() = sequence { // this: SequenceScope<String>
yield("Hi")
yield(":))")
}
val words = hi()
for (word in words) {
println(word)
}
// func getUser(userid: String, continuation: Continuation)
suspend fun getUser(usid: String) {
// label: 0
val token = apiToken(sm)
// label: 1
val user = findUser(usid, sm.token, sm)
// label: 2
// Do what you want with the user
}
}
@LucianoPAlmeida
LucianoPAlmeida / getuser.kt
Created July 20, 2019 19:03
Kotlin coroutines
suspend fun getUser(usid: String) {
val token = apiToken()
val user = findUser(usid, token)
}
// func getUser(userid: String, continuation: Continuation)
suspend fun getUser(usid: String) {
val sm = CoroutineImpl {}
when (sm.label) {
0 -> {
apiToken(sm)
sm.label = 1
}
1 -> {