Do we need Consumer/Supplier in Kotlin

I am new to FP, In Java 8, we have consumer/supplier like this:

fun main(args: Array<String>) {
    randomProvier(
            Consumer {
                numberPrinter(Supplier {
                    it
                })
            }
    )
    //Or this
    numberPrinter(Supplier {
        randomProvier(Consumer { })
    })
}

fun randomProvier(c: Consumer<Double>): Double {
    var n = Math.random()
    c.accept(n)
    return n
}

fun numberPrinter(s: Supplier<Double>) {
    println(s.get())
}

But in Kotlin we can do just like this:

fun main(args: Array<String>) {
    randomProvier { numberPrinter {it} }
    //Or this
    numberPrinter { randomProvier{} }
}

fun randomProvier(c: (Double) -> Unit) : Double{
    var n =Math.random()
    c(n)
    return n
}

fun numberPrinter(s: () -> Double){
    println(s())
}

Does that mean that we don’t need Consumer/Supplier anymore ?

Yes, them are not required.

typealias Producer<T> = () -> T
typealias Consumer<T> = (T) -> Unit

Required for Stream reuse cases.

To avoid the exception: “java.lang.IllegalStateException: stream has already been operated upon or closed”

What do you mean by this? Why do we need to reuse Java Streams in Kotlin?

When it is necessary to use stream in kotlin, reuse it is a option.
How do you read a file on kotlin?

I don’t really understand what do you mean. How is Consumer/Supplier required to reuse a Stream?

Also, I think this case is really irrelevant. Stream is only available on JVM target and if we are targeting JVM then we have Consumer/Supplier as well, because they’re part of the Java stdlib. The question is: do we need Consumer/Supplier interfaces in Kotlin stdlib? I guess no, it would be redundant to function types.

Sorry, I’m misunderstood your message. I thought you was talking about Java Stream API.