Package

purescript-shuffle

Repository
joellefkowitz/shuffle
License
MIT
Uploaded by
pacchettibotti
Published on
2025-01-15T22:01:41Z

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 ∷ ∀ a. Array a → Effect (Array a)

import Effect.Shuffle (shuffle)

shuffle ["a", "b", "c"]
["b", "c", "a"]

Often when you want pick an element from an array at random the underlying type will be a Monoid. This means that if the array is empty there is an suitable fallback:

pick ∷ ∀ a. Monoid a ⇒ Array a → Effect a

import Effect.Shuffle (pick)

pick ["a", "b", "c"]
"b"
pick []
""

Alternatively you can provide a fallback directly with pickOr:

pickOr ∷ ∀ a. a → Array a → Effect a

import Effect.Shuffle (pickOr)

pickOr 0 [1, 2, 3]
2
pickOr 0 []
0

If you want to explicitly receive a Maybe you can use pickMaybe:

pickMaybe ∷ ∀ a. Array a → Effect (Maybe a)

import Effect.Shuffle (pickMaybe)

pickMaybe ["a", "b", "c"]
Just "b"
pickMaybe []
Nothing

If your array is non-empty then you can use pickNonEmpty:

pickNonEmpty ∷ ∀ a. NonEmptyArray a → Effect a

import Effect.Shuffle (pickNonEmpty)

pickNonEmpty (cons' "a" [ "b", "c" ])
"b"

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