Go's "multiple return values" feature, can be used for several purposes. Among them for failure reporting to the function caller. Go has two conventions for failure reporting, but currently, no clear convention for which to use when. I've encountered different programmers that prefer different choices in different cases. In this article, we will discuss the two, and try to make the process of choosing our next function signature more conscious.
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
| max = ARGV[0].to_i | |
| 1.upto(max) do |i| | |
| if i % 15 == 0 | |
| puts "FizzBuzz" | |
| elsif i % 3 == 0 | |
| puts "Fizz" | |
| elsif i % 5 == 0 | |
| puts "Buzz" | |
| else |
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
| package config | |
| import ( | |
| "crypto/rand" | |
| "crypto/rsa" | |
| "crypto/x509" | |
| "encoding/pem" | |
| "io/ioutil" | |
| "github.com/CodeCollaborate/Server/utils" |
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 kotlinx.coroutines.experimental.DefaultDispatcher | |
| import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
| import kotlinx.coroutines.experimental.channels.consumeEach | |
| import kotlinx.coroutines.experimental.channels.produce | |
| import kotlinx.coroutines.experimental.delay | |
| import kotlinx.coroutines.experimental.runBlocking | |
| import kotlin.coroutines.experimental.CoroutineContext | |
| fun <T> ReceiveChannel<T>.debounce( | |
| wait: Long = 300, |
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 kotlinx.coroutines.experimental.* | |
| import kotlinx.coroutines.experimental.channels.ReceiveChannel | |
| import kotlinx.coroutines.experimental.channels.consumeEach | |
| import kotlinx.coroutines.experimental.channels.produce | |
| import kotlin.coroutines.experimental.CoroutineContext | |
| fun <E> ReceiveChannel<E>.debounce( | |
| wait: Long = 50, | |
| context: CoroutineContext = DefaultDispatcher | |
| ): ReceiveChannel<E> = produce(context) { |
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
| /* | |
| * Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license. | |
| */ | |
| import android.location.Location | |
| import com.google.android.gms.location.LocationCallback | |
| import com.google.android.gms.location.LocationRequest | |
| import com.google.android.gms.location.LocationResult | |
| import com.google.android.gms.location.LocationServices | |
| import kotlinx.coroutines.CancellationException |