unfoldable-0.2.0: Class of data structures that can be unfolded from a seed value.

Safe HaskellSafe-Infered

Data.Splittable

Synopsis

Documentation

class Splittable s whereSource

Splittable datatypes are datatypes that can be used as seeds for unfolds.

Methods

split :: Int -> s -> [s]Source

split n s splits the seed s in n seeds.

choose :: [s -> x] -> s -> xSource

choose fs s uses part of the seed s to choose a function from the list fs, and passes the remainder to that function.

getInt :: s -> IntSource

Convert the seed value to an int.

Instances

Splittable Integer

The Integer instance uses modulo to choose, and splits breadth-first by distributing bits in a round-robin fashion.

Splittable StdGen

Choose randomly

Splittable Right

Always choose the last item.

Splittable Left

Always choose the first item.

Splittable s => Splittable (Dual s)

Reverse the split output and the choose input.

(Splittable a, Splittable b) => Splittable (Either a b)

Choose between 2 ways to split and choose.

(Splittable a, Splittable b) => Splittable (a, b)

The (a, b) instance uses only a for choose and b for getInt.

boundedEnum :: forall s a. (Splittable s, Bounded a, Enum a) => s -> aSource

If a datatype is bounded and enumerable, we can use getInt to produce a value from a seed.

data Left Source

Constructors

L 

Instances

Splittable Left

Always choose the first item.

data Right Source

Constructors

R 

Instances

Splittable Right

Always choose the last item.