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

arrow.data.Const.kt Maven / Gradle / Ivy

There is a newer version: 0.8.2
Show newest version
package arrow.data

import arrow.*
import arrow.core.Option
import arrow.typeclasses.Applicative
import arrow.typeclasses.Semigroup

fun  ConstKind.value(): A = this.ev().value

@higherkind data class Const(val value: A) : ConstKind {

    @Suppress("UNCHECKED_CAST")
    fun  retag(): Const = this as Const

    fun  traverse(f: (T) -> HK, FA: Applicative): HK> = FA.pure(retag())

    fun  traverseFilter(f: (T) -> HK>, FA: Applicative): HK> = FA.pure(retag())

    companion object {
        fun  pure(a: A): Const = Const(a)
    }
}

fun  ConstKind.combine(that: ConstKind, SG: Semigroup): Const = Const(SG.combine(this.value(), that.value()))

fun  ConstKind.ap(ff: ConstKind U>, SG: Semigroup): Const = ff.ev().retag().combine(this.ev().retag(), SG)

fun  A.const(): Const = Const(this)