Package

purescript-shuffle

Repository
joellefkowitz/shuffle
License
MIT
Uploaded by
pacchettibotti
Published on
2025-10-19T13:58:12Z

Shuffle and pick elements from arrays.

Review Version Quality

Installing

spago install shuffle

Usage

You can shuffle an array and the result will be contained inside an Effect:

shuffle ∷ ∀ f a. Foldable f ⇒ Unfoldable f ⇒ f a → Effect (f a)

import Effect.Shuffle (shuffle)

do
  ... <- shuffle ["a", "b", "c"]
  -- ["b", "c", "a"]

You can similarly pick an element from an array at random:

pick ∷ ∀ f a. Foldable f ⇒ Unfoldable f ⇒ f a → Effect (Maybe a)

import Effect.Shuffle (pick)

do
  ... <- pick ["a", "b", "c"]
  -- Just "b"

You can provide a fallback directly with pickOr:

pickOr ∷ ∀ f a. Foldable f ⇒ Unfoldable f ⇒ a → f a → Effect a

import Effect.Shuffle (pickOr)

do
  ... <- pickOr "" ["a", "b", "c"]
  -- "b"

If the underlying type is a Monoid there is an suitable fallback automatically:

pickMonoid ∷ ∀ f a. Foldable f ⇒ Unfoldable f ⇒ Monoid a ⇒ f a → Effect a

import Effect.Shuffle (pickMonoid)

strings :: Array String
strings = []

do
  ... <- pickMonoid strings
  -- ""

If you have a NonEmptyArray you can pick an element without needing a fallback:

pickNonEmpty ∷ ∀ a. NonEmptyArray a → Effect a

import Data.Array.NonEmpty (singleton)
import Effect.Shuffle (pickNonEmpty)

do
  ... <- pickNonEmpty $ singleton "a"
  -- "a"

Documentation

Documentation and more detailed examples are hosted on Pursuit.

Tooling

Dependencies

To install dependencies:

yarn install
yarn spago install

Tests

To run tests:

yarn spago test

Documentation

To generate the documentation locally:

yarn spago docs

Linters

To run linters:

yarn lint

Formatters

To run formatters:

yarn format

Contributing

Please read this repository's Code of Conduct which outlines our collaboration standards and the Changelog for details on breaking changes that have been made.

This repository adheres to semantic versioning standards. For more information on semantic versioning visit SemVer.

Bump2version is used to version and tag changes. For example:

bump2version patch

Contributors

Remarks

Lots of love to the open source community!

Be kind to your mind Love each other It's ok to have a bad day
Modules
Effect.Shuffle
Dependencies