Skip to content

Commit dc570e1

Browse files
welcome back (<|>) import :p
1 parent 789ae97 commit dc570e1

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/Data/Unfoldable/Trivial/Internal.purs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Data.Unfoldable
3030
)
3131
import Data.Tuple (uncurry, fst, snd)
3232
import Data.Tuple.Nested ((/\), type (/\))
33-
import Data.Maybe (Maybe(..), maybe', fromMaybe)
33+
import Data.Maybe (Maybe(..), maybe')
3434
import Data.Exists (Exists, mkExists, runExists)
3535
import Data.Bifunctor (lmap)
3636
import Data.Functor.Invariant (class Invariant, imapF)
@@ -42,7 +42,7 @@ import Data.Filterable
4242
, filterMapDefault
4343
)
4444
import Data.Either (Either(..), either)
45-
import Control.Alternative (class Alt, class Plus, class Alternative)
45+
import Control.Alternative (class Alt, class Plus, class Alternative, (<|>))
4646
import Control.Lazy (class Lazy)
4747
import Test.QuickCheck.Arbitrary (class Arbitrary, class Coarbitrary, arbitrary)
4848
import Test.QuickCheck.Gen (sized)
@@ -211,13 +211,12 @@ instance trivialAlt :: Alt Trivial where
211211
alt :: forall a. Trivial a -> Trivial a -> Trivial a
212212
alt t = untrivial (untrivial eAlt t)
213213
where eAlt :: forall b b'. Generator a b -> b -> Generator a b' -> b' -> Trivial a
214-
eAlt f seed f' seed' = unfoldr smooshed $ Just seed /\ seed'
215-
where smooshed :: Maybe b /\ b' -> Maybe (a /\ Maybe b /\ b')
216-
smooshed (Just b /\ b') = do
217-
let dom = f b
218-
a' /\ nb' <- f' b'
219-
Just $ fromMaybe a' (fst <$> dom) /\ map snd dom /\ nb'
220-
smooshed (Nothing /\ b') = map (Nothing /\ _) <$> f' b'
214+
eAlt f seed f' seed' = unfoldr smooshed $ Just seed /\ Just seed'
215+
where smooshed :: Maybe b /\ Maybe b' -> Maybe (a /\ Maybe b /\ Maybe b')
216+
smooshed (b /\ b') = (map fst top <|> map fst me) <#> (_ /\ map snd top /\ map snd me)
217+
where top = f =<< b
218+
me = f' =<< b'
219+
221220

222221

223222
instance trivialMonoid :: Monoid (Trivial a) where

test/Main.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ foldSuite = describe "foldl foldr" do
208208
appendSuite :: Spec Unit
209209
appendSuite = describe "Semigroup and Alternative" do
210210
let qc = quickCheck' 20 :: forall p. Testable p => p -> _
211-
it "Alt Trivial agrees with Alt Array" do
212-
qc \(a :: Trivial Char) b -> arrgh (a <|> b) === arrgh a <|> arrgh b
213-
it "Alt Trivial1 agrees with Alt Array" do
214-
qc \(a :: Trivial1 Char) b -> arrgh1 (a <|> b) === [] <|> arrgh1 a <|> arrgh1 b
211+
it "Semigroup (Trivial a) agrees with Alt Array" do
212+
qc \(a :: Trivial Char) b -> arrgh (a <> b) === arrgh a <|> arrgh b
213+
it "Semigroup (Trivial1 a) agrees with Alt Array" do
214+
qc \(a :: Trivial1 Char) b -> arrgh1 (a <> b) === arrgh1 a <|> arrgh1 b
215215
it "append1 agrees with Alt Array" do
216216
qc \(a :: Trivial1 Char) (b :: Trivial Char) -> arrgh1 (a `append1` b) === arrgh1 a <|> arrgh b
217217
it "append1' agrees with Alt Array" do

0 commit comments

Comments
 (0)