@@ -7,11 +7,15 @@ import Data.Eq (class Eq1)
7
7
import Data.Foldable (class Foldable )
8
8
import Data.FoldableWithIndex (class FoldableWithIndex )
9
9
import Data.FunctorWithIndex (class FunctorWithIndex )
10
+ import Data.Maybe (Maybe , fromJust , isNothing )
10
11
import Data.Ord (class Ord1 )
11
12
import Data.Semigroup.Foldable (class Foldable1 , foldMap1Default )
12
13
import Data.Semigroup.Traversable (class Traversable1 , sequence1Default )
13
14
import Data.Traversable (class Traversable )
14
15
import Data.TraversableWithIndex (class TraversableWithIndex )
16
+ import Data.Tuple (Tuple , fst , snd )
17
+ import Data.Unfoldable1 (class Unfoldable1 )
18
+ import Partial.Unsafe (unsafePartial )
15
19
16
20
newtype NonEmptyArray a = NonEmptyArray (Array a )
17
21
@@ -24,6 +28,8 @@ derive newtype instance eq1NonEmptyArray :: Eq1 NonEmptyArray
24
28
derive newtype instance ordNonEmptyArray :: Ord a => Ord (NonEmptyArray a )
25
29
derive newtype instance ord1NonEmptyArray :: Ord1 NonEmptyArray
26
30
31
+ derive newtype instance semigroupNonEmptyArray :: Semigroup (NonEmptyArray a )
32
+
27
33
derive newtype instance functorNonEmptyArray :: Functor NonEmptyArray
28
34
derive newtype instance functorWithIndexNonEmptyArray :: FunctorWithIndex Int NonEmptyArray
29
35
@@ -34,10 +40,13 @@ instance foldable1NonEmptyArray :: Foldable1 NonEmptyArray where
34
40
foldMap1 = foldMap1Default
35
41
fold1 = fold1Impl (<>)
36
42
43
+ instance unfoldable1NonEmptyArray :: Unfoldable1 NonEmptyArray where
44
+ unfoldr1 = unfoldr1Impl isNothing (unsafePartial fromJust) fst snd
45
+
37
46
derive newtype instance traversableNonEmptyArray :: Traversable NonEmptyArray
38
47
derive newtype instance traversableWithIndexNonEmptyArray :: TraversableWithIndex Int NonEmptyArray
39
48
40
- instance traversable1NonEmptyArray :: Traversable1 NonEmptyArray where
49
+ instance traversable1NonEmptyArray :: Traversable1 NonEmptyArray where
41
50
traverse1 = traverse1Impl apply map
42
51
sequence1 = sequence1Default
43
52
@@ -51,9 +60,19 @@ derive newtype instance monadNonEmptyArray :: Monad NonEmptyArray
51
60
52
61
derive newtype instance altNonEmptyArray :: Alt NonEmptyArray
53
62
54
- -- we use FFI here to avoid the unnecessary copy created by `tail`
63
+ -- we use FFI here to avoid the unncessary copy created by `tail`
55
64
foreign import fold1Impl :: forall a . (a -> a -> a ) -> NonEmptyArray a -> a
56
65
66
+ foreign import unfoldr1Impl
67
+ :: forall a b
68
+ . (forall x . Maybe x -> Boolean )
69
+ -> (forall x . Maybe x -> x )
70
+ -> (forall x y . Tuple x y -> x )
71
+ -> (forall x y . Tuple x y -> y )
72
+ -> (b -> Tuple a (Maybe b ))
73
+ -> b
74
+ -> NonEmptyArray a
75
+
57
76
foreign import traverse1Impl
58
77
:: forall m a b
59
78
. (forall a' b' . (m (a' -> b' ) -> m a' -> m b' ))
0 commit comments