• t

    Tom Adam

    3 years ago
    When it comes to iteration and ranges one can write something like:
    (5 downTo 3  step 3).forEach { println(it) }
    or
    (5 downTo 3).filter { it % 2 == 0}
            .forEach { println(it) }
    However, if filter would be infix, one could also write
    (5 downTo 3  filter { it % 2 == 0})
            .forEach { println(it) }
    which would be totally in sync with the infix syntax of
    step
    , and possibly would mean a more consistent API. Any thoughts?
    t
    elizarov
    +3
    9 replies
    Copy to Clipboard
  • ilya.gorbunov

    ilya.gorbunov

    3 years ago
    📣 Please welcome our first step to the standard way of working with time in Kotlin:Duration and time interval measurement API https://github.com/Kotlin/KEEP/blob/durations/proposals/stdlib/durations-and-clocks.md The proposal can be discussed in this issue: https://github.com/Kotlin/KEEP/issues/190
    ilya.gorbunov
    j
    +4
    26 replies
    Copy to Clipboard
  • m

    Marc Knaup

    3 years ago
    What about moving
    Url
    from ktor.http to stdlib? 🤔 • it's very commonly needed • it's for more than HTTP or even networking • Ktor is an implementation detail - could also be another HTTP client • when using different libraries (networking and other) they all use different
    Url
    classes because there's no common denominator
    m
    natpryce
    +1
    10 replies
    Copy to Clipboard
  • voddan

    voddan

    3 years ago
    For my use case I wanted to have
    list.take(n)
    in a way that would remember the last accessed position and give me the next
    m
    elements on a consecutive
    list.take(m)
    https://stackoverflow.com/questions/56578561/how-can-i-take-varying-chunks-out-of-a-kotlin-sequence My solution was to produce an
    Iterator
    from the list and use
    take(n)
    on it. Unfortunately that produces a of-by-one error because of the way
    take
    is implemented in stdlib. To fix this one would have to modify a few lines in the [implementation](https://github.com/JetBrains/kotlin/blob/41ce88cb9b8e32da6121e79c229b2563f46fd161/libraries/stdlib/common/src/generated/_Collections.kt#L778 ) replacing
    for (item in this) {
            if (count++ == n)
                break
            list.add(item)
        }
    with
    for (item in this) {
            list.add(item)
            if (++count == n)
                break
        }
    Could such a change be considered?
    voddan
    ilya.gorbunov
    3 replies
    Copy to Clipboard
  • b

    bbaldino

    3 years ago
    is there a collection in kotlin like java's
    Vector
    which will default instantiate the instances? i want to create a collection of a generic type (from a class generic param) but don't want to have to pass in a lambda to tell the class how to default initialize. i.e.:
    class Foo<StatType> {
        val stats = Vector<StatType>(8)
    }
    b
    Pavlo Liapota
    +1
    8 replies
    Copy to Clipboard
  • e

    elect

    3 years ago
    onEachIndexed
    ?
    e
    Hullaballoonatic
    +1
    3 replies
    Copy to Clipboard
  • e

    elect

    3 years ago
    also
    operator fun <R> KMutableProperty0<R>.setValue(host: Any?, property: KProperty<*>, value: R) = set(value)
    operator fun <R> KMutableProperty0<R>.getValue(host: Any?, property: KProperty<*>): R = get()
    for setting local
    var
    from variable references
    e
    gildor
    +1
    9 replies
    Copy to Clipboard
  • Hullaballoonatic

    Hullaballoonatic

    3 years ago
    Number
    changed from Abstract Class to Interface, given it is purely composed of abstract methods.
    Hullaballoonatic
    karelpeeters
    +3
    30 replies
    Copy to Clipboard
  • gregorbg

    gregorbg

    3 years ago
    What is the reason for
    Map<K, V>.filterValues
    working directly on the values (i.e. it expects
    (V) -> T
    ) as opposed to
    Map<K, V>.mapValues
    working on the entire entry (i.e. it expects
    (Map.Entry<K, V>) -> T
    )? Same question applies to the signature of
    filterKeys
    vs.
    mapKeys
    and similar functions.
    gregorbg
    voddan
    +1
    4 replies
    Copy to Clipboard
  • g

    guenther

    3 years ago
    Floating Point Rounding: With the JVM it's a mess to round an e.g.
    Double (12.456778)
    to a certain precision. This would be something really useful like
    12.34567.roundToPrecision(...)
    (don't nail me on the function name, I'd just want to express that rounding would be useful. What do you think?
    g
    karelpeeters
    +3
    32 replies
    Copy to Clipboard