Skip to content

Commit 0a7b628

Browse files
committed
add Bifoldable for Interval
1 parent 266d481 commit 0a7b628

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Data/Interval/Interval.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Prelude
1818
import Control.Extend (class Extend)
1919
import Data.Bifunctor (class Bifunctor, bimap)
2020
import Data.Foldable (class Foldable, foldrDefault, foldMapDefaultL)
21+
import Data.Bifoldable (class Bifoldable, bifoldrDefault, bifoldMapDefaultL)
2122
import Data.List (List(..), (:))
2223
import Data.Maybe (Maybe)
2324
import Data.Monoid (class Monoid, mempty)
@@ -56,6 +57,14 @@ instance foldableInterval ∷ Foldable (Interval d) where
5657
foldr x = foldrDefault x
5758
foldMap = foldMapDefaultL
5859

60+
instance bifoldableIntervalBifoldable Interval where
61+
bifoldl _ f z (StartEnd x y) = (z `f` x) `f` y
62+
bifoldl g f z (DurationEnd d x) = (z `g` d) `f` x
63+
bifoldl g f z (StartDuration x d) = (z `g` d) `f` x
64+
bifoldl g _ z (JustDuration d) = z `g` d
65+
bifoldr x = bifoldrDefault x
66+
bifoldMap = bifoldMapDefaultL
67+
5968
instance traversableIntervalTraversable (Interval d) where
6069
traverse f (StartEnd x y) = StartEnd <$> f x <*> f y
6170
traverse f (DurationEnd d x) = f x <#> DurationEnd d

0 commit comments

Comments
 (0)