@@ -13,11 +13,28 @@ import Data.Semigroup.Traversable (class Traversable1, sequence1)
1313import Data.Tuple (Tuple (..), fst , snd )
1414import Partial.Unsafe (unsafePartial )
1515
16- -- | This class identifies non-empty data structures which can be _unfolded_.
16+ -- | This class identifies data structures which can be _unfolded_.
1717-- |
18- -- | The generating function `f` corresponds to the `uncons` operation of a
19- -- | non-empty list or array; it always return a value, and then optionally
20- -- | a value to continue unfolding from.
18+ -- | The generating function `f` in `unfoldr1 f` corresponds to the `uncons`
19+ -- | operation of a non-empty list or array; it always returns a value, and
20+ -- | then optionally a value to continue unfolding from.
21+ -- |
22+ -- | Note that, in order to provide an `Unfoldable1 t` instance, `t` need not
23+ -- | be a type which is guaranteed to be non-empty. For example, the fact that
24+ -- | arrays can be empty does not prevent us from providing an `Unfoldable1
25+ -- | Array` instance. However, the result of `unfoldr1` should always be
26+ -- | non-empty.
27+ -- |
28+ -- | Every type which has an `Unfoldable` instance can be given an
29+ -- | `Unfoldable1` instance (and, in fact, is required to, because
30+ -- | `Unfoldable1` is a superclass of `Unfoldable`). However, there are types
31+ -- | which have `Unfoldable1` instances but cannot have `Unfoldable` instances.
32+ -- | In particular, types which are guaranteed to be non-empty, such as
33+ -- | `NonEmptyArray`, cannot be given `Unfoldable` instances.
34+ -- |
35+ -- | The utility of this class, then, is that it provides an `Unfoldable`-like
36+ -- | interface while still permitting instances for guaranteed-non-empty types
37+ -- | like `NonEmptyArray`.
2138class Unfoldable1 t where
2239 unfoldr1 :: forall a b . (b -> Tuple a (Maybe b )) -> b -> t a
2340
0 commit comments