Module

Data.Unfoldable.Trivial.Internal

Package
purescript-trivial-unfold
Repository
UnrelatedString/purescript-trivial-unfold

This module provides the Trivial type as an existentially quantified dumb wrapper around unfold, which can be inspected and manipulated to implement various typeclasses and the utilities in Data.Unfoldable.Trivial.

This module also contains the implementations of utilities which rely on directly inspecting Trivial values and are re-exported by Data.Unfoldable.Trivial. Use this module directly only if you intend to directly inspect Trivial values yourself.

#Trivial Source

newtype Trivial a

A type wrapping unfoldr calls, existentially quantified over the seed type so that it can be ignored in the type constructor. Its Unfoldable instance means that it can directly be constructed by calling unfoldr.

Instances

  • Unfoldable Trivial

    Wraps both arguments to unfoldr in an UnfoldrCall.

  • Unfoldable1 Trivial
  • Functor Trivial
  • Invariant Trivial
  • Foldable Trivial

    The raison d'être for Trivial. Allows folding polymorphic Unfoldables as they generate.

    foldr uses a default implementation and may be inefficient. Note also that this enables the use of sequence_ despite the lack of a Traversable instance, which is not provided because it would require forcing and accumulating every value, at which point any would-be user is better off with an actual container.

  • (Arbitrary a, Coarbitrary a) => Arbitrary (Trivial a)

    Guaranteed finite.

  • Lazy (Trivial a)
  • Compactable Trivial
  • Filterable Trivial
  • Semigroup (Trivial a)

    Concatenation.

    Do not use this to create a data structure. Please use Data.List.Lazy instead.

  • Plus Trivial
  • Alt Trivial

    Not concatenation! (<|>) clobbers a prefix of the right argument of the length of the left in order to satisfy the Alternative laws. (Thanks to @xgrommx's implementation in ZipList!)

  • Monoid (Trivial a)
  • Apply Trivial

    Zipwith; chosen over the Monad-compatible nondet choice used for Array etc. because that would require effectively forcing one argument and either re-evaluating it constantly or storing its elements in a real container at which point please please please just do that without using Trivial. Length is the minimum of the arguments' lengths.

  • Applicative Trivial

    Infinitely cycles to satisfy the Applicative laws! If you just want one element, use singleton instead.

  • Alternative Trivial
  • (Eq a) => Eq (Trivial a)

    Does not and cannot memoize the values being produced to compare. Please consider using Data.List.Lazy or your strict container of choice instead if you have any intention of using this for anything else.

  • (Ord a) => Ord (Trivial a)
  • Eq1 Trivial
  • Ord1 Trivial
  • (Show a) => Show (Trivial a)

#Generator Source

type Generator a b = b -> Maybe (a /\ b)

Alias for the generator function passed to unfoldr.

#trivial Source

trivial :: forall a. Trivial a -> Trivial a

Specializes its argument to Trivial.

#untrivial Source

untrivial :: forall a c. (forall b. Generator a b -> b -> c) -> Trivial a -> c

Convenience function for inspecting Trivial values. Calls the function argument on the contents of the inner Exists.

#turbofish Source

turbofish :: forall a b. (Trivial a -> b) -> Trivial a -> b

Function application specialized to a Trivial argument, at the same precedence as ($).

Inspired by the Rust syntax of the same name, often used in the analogous context of collecting from an iterator.

#(::<*>) Source

Operator alias for Data.Unfoldable.Trivial.Internal.turbofish (right-associative / precedence 0)

#unfoldr1Default Source

unfoldr1Default :: forall a b t. Unfoldable t => (b -> a /\ (Maybe b)) -> b -> t a

Provides a default implementation of unfoldr1 using unfoldr to satisfy the superclass bound on Unfoldable.

#runTrivial Source

runTrivial :: forall a u. Unfoldable u => Trivial a -> u a

Converts to any other Unfoldable. Can also be seen as evaluating the inner UnfoldrCall.

This is only useful in implementing utility functions. In all other cases, simply use the desired type directly.