• n

    napperley

    3 years ago
    This is a repost (from #general) about extending the Boolean type: https://kotlinlang.slack.com/archives/C0922A726/p1569444125303200
    n
    ilya.gorbunov
    3 replies
    Copy to Clipboard
  • m

    Marc Knaup

    3 years ago
    Can we kotlinify Java’s
    Objects.hash(foo, bar, baz, …)
    to something like this?
    hash { foo x bar x baz x … }
    Just the boxing is a little tricky as well as getting it to work with just a single non-
    Int
    value without introducing boxing. Implementation:
    inline fun hash(block: HashScope.() -> Int) =
    	HashScope.block()
    
    object HashScope {
    
    	inline infix fun Any?.x(hashable: Any?) =
    		(31 * hashCode()) + hashable.hashCode()
    
    	inline infix fun Any?.x(hashable: Int) =
    		(31 * hashCode()) + hashable
    
    	inline infix fun Int.x(hashable: Any?) =
    		(31 * this) + hashable.hashCode()
    
    	inline infix fun Int.x(hashable: Int) =
    		(31 * this) + hashable
    }
    
    class Example(val foo: String, val bar: List<Any>?, val baz: Int) {
    
    	override fun hashCode() =
    		hash { foo x bar x baz }
    }
    m
    j
    7 replies
    Copy to Clipboard
  • m

    Marc Knaup

    3 years ago
    Another question: Why doesn’t
    ClosedRange
    have operators for destructuring?
    m
    marcinmoskala
    6 replies
    Copy to Clipboard
  • Dominaezzz

    Dominaezzz

    2 years ago
    Proposal.
    @kotlin.internal.InlineOnly
    public inline fun buildByteArray(builderAction: ByteArrayOutputStream.() -> Unit): ByteArray
    Dominaezzz
    j
    6 replies
    Copy to Clipboard
  • Mark

    Mark

    2 years ago
    Is there a better way to write this:
    val CJK_EXTENSIONS_STR = fun (): String {
        var result = "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_A}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_B}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_C}\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_D}"
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            result += "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_E}"
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                result += "\\p{InCJK_UNIFIED_IDEOGRAPHS_EXTENSION_F}"
            }
        }
        return result
    }.invoke()
    Mark
    m
    12 replies
    Copy to Clipboard
  • Dominaezzz

    Dominaezzz

    2 years ago
    Is there a YouTrack issue for
    Closeable
    in stdlib? I remember the verdict being stdlib itself doesn't use it so it won't provide it, but there should a ticket somewhere.
    Dominaezzz
    j
    +1
    4 replies
    Copy to Clipboard
  • s

    spand

    2 years ago
    Any particular reason
    Iterable<T>.groupByTo
    requires destination to be a list and not a collection ?
    s
    Dominaezzz
    2 replies
    Copy to Clipboard
  • Bob Glamm

    Bob Glamm

    2 years ago
    Suggest adding
    fun Pair<A, B>.flip(): Pair<B, A> = Pair(second, first)
    to the standard library
    Bob Glamm
    miha-x64
    +1
    4 replies
    Copy to Clipboard
  • p

    PHondogo

    2 years ago
    Hi! I couldn't find in stdlib common implementation fo formatting Double to String by pattern. Is there any crossplatform solution for that?
    p
    gildor
    5 replies
    Copy to Clipboard
  • LeoColman

    LeoColman

    2 years ago
    Encoding/Decoding Base64 without depending on Java methods
    LeoColman
    s
    2 replies
    Copy to Clipboard