From efcb32a1708578ad6ca0f6d05ff3d0ce290eb57f Mon Sep 17 00:00:00 2001 From: Tomasz Rybarczyk Date: Mon, 30 Jan 2023 11:27:53 +0100 Subject: [PATCH] Add Unfoldable1 instance --- spago.dhall | 1 + src/Data/Array/AtLeast.purs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spago.dhall b/spago.dhall index aa3f524..276c7c2 100644 --- a/spago.dhall +++ b/spago.dhall @@ -10,6 +10,7 @@ , "partial" , "prelude" , "quickcheck" + , "unfoldable" , "unsafe-coerce" ] , packages = ./packages.dhall diff --git a/src/Data/Array/AtLeast.purs b/src/Data/Array/AtLeast.purs index 6ef4d8e..cee9405 100644 --- a/src/Data/Array/AtLeast.purs +++ b/src/Data/Array/AtLeast.purs @@ -71,14 +71,16 @@ import Data.FastVect.FastVect as FV import Data.Foldable (class Foldable) import Data.FoldableWithIndex (class FoldableWithIndex) import Data.FunctorWithIndex (class FunctorWithIndex) -import Data.Int.AtLeast (fromLength) as IntAL import Data.Int.AtLeast (IntAL, fromInt', toInt) +import Data.Int.AtLeast (fromLength) as IntAL import Data.Maybe (Maybe(Nothing, Just), fromJust) import Data.Reflectable (class Reflectable, reflectType) import Data.Semigroup.Foldable (class Foldable1) import Data.Semigroup.Foldable as Foldable1 import Data.Traversable (class Traversable) import Data.TraversableWithIndex (class TraversableWithIndex) +import Data.Unfoldable (unfoldr1) +import Data.Unfoldable1 (class Unfoldable1) import Partial.Unsafe (unsafePartial) import Prim.Int (class Add, class Compare, class Mul) import Prim.Ordering (EQ, GT, LT) @@ -112,6 +114,9 @@ instance Compare n 0 GT => Foldable1 (ArrayAL n) where foldr1 f xs = Foldable1.foldr1 f $ toNonEmptyArray xs foldl1 f xs = Foldable1.foldl1 f $ toNonEmptyArray xs +instance Unfoldable1 (ArrayAL 1) where + unfoldr1 f = fromNonEmptyArray <<< unfoldr1 f + instance Apply (ArrayAL n) where apply (ArrayAL fab) (ArrayAL a) = ArrayAL (Array.zipWith ($) fab a)