All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.jetbrains.letsPlot.livemap.containers.SingletonCollection.kt Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package org.jetbrains.letsPlot.livemap.containers

fun  singletonCollection(value: T): Collection = SingletonCollection(value)

class SingletonCollection(private val item: T) : AbstractCollection() {
    override val size get() = 1

    override fun iterator(): Iterator = SingleItemIterator(item)

    private class SingleItemIterator(private val value: T) : AbstractIterator() {
        private var requested = false
        override fun computeNext() {
            when (requested) {
                false -> setNext(value)
                true -> done()
            }

            requested = true
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy