Repeat

The Repeat typeclass extends the Zip typeclass with a way to repeat the structure.

Main Combinators

repeat

Provides a structure that can be used to zip with. The structure repeats the provided value and is potentially infinite.

fun <A> repeat(a: A): Kind<F, A>

import arrow.core.extensions.*
import arrow.core.extensions.sequencek.repeat.repeat
import arrow.core.*

val seq = generateSequence(0) { it + 1 }.k()
SequenceK.repeat().run {
    repeat("Item").zip(seq).fix().take(5).toList()
}
// [(Item, 0), (Item, 1), (Item, 2), (Item, 3), (Item, 4)]

Laws

Arrow provides RepeatLaws in the form of test cases for internal verification of lawful instances and third party apps creating their own Repeat instances.

Creating your own Repeat instances

Arrow already provides Repeat instances for common datatypes (e.g. Option, SequenceK). See their implementations and accompanying testcases for reference.

See Deriving and creating custom typeclass

Additionally all instances of Repeat implement the Zip typeclass directly since they are all subtypes of Zip

Data types

Module Data types
arrow.core Id, Option, SequenceK

Type Class Hierarchy

Do you like Arrow?

Arrow Org
<