{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
module IntervalAlgebra.IntervalUtilities
(
combineIntervals
, combineIntervalsL
, combineIntervalsFromSorted
, combineIntervalsFromSortedL
, rangeInterval
, gaps
, gapsL
, gapsWithin
, foldMeetingSafe
, formMeetingSequence
, nothingIf
, nothingIfNone
, nothingIfAny
, nothingIfAll
, filterBefore
, filterMeets
, filterOverlaps
, filterFinishedBy
, filterContains
, filterStarts
, filterEquals
, filterStartedBy
, filterDuring
, filterFinishes
, filterOverlappedBy
, filterMetBy
, filterAfter
, filterDisjoint
, filterNotDisjoint
, filterConcur
, filterWithin
, filterEncloses
, filterEnclosedBy
, lookback
, lookahead
, makeGapsWithinPredicate
, pairGaps
, anyGapsWithinAtLeastDuration
, allGapsWithinLessThanDuration
, relations
, relationsL
, intersect
, clip
, durations
) where
import safe Control.Applicative (Applicative (pure),
liftA2, (<$>), (<*>))
import qualified Control.Foldl as L
import safe Control.Monad (Functor (fmap))
import safe Data.Bool (Bool (..), not, otherwise,
(&&), (||))
import safe Data.Eq (Eq ((==)))
import safe Data.Foldable (Foldable (foldl', foldr, null, toList),
all, any, or)
import safe Data.Function (flip, ($), (.))
import safe Data.List (map, reverse, sortOn)
import safe Data.Maybe (Maybe (..), maybe,
maybeToList)
import safe Data.Monoid (Monoid (mempty))
import safe Data.Ord (Ord (max, min), (<), (>=))
import safe Data.Semigroup (Semigroup ((<>)))
import safe Data.Traversable (Traversable (sequenceA))
import safe Data.Tuple (fst, uncurry)
import safe GHC.Int (Int)
import safe GHC.Show (Show)
import safe IntervalAlgebra.Core (ComparativePredicateOf1,
ComparativePredicateOf2,
Interval,
IntervalCombinable ((><)),
IntervalRelation (..),
IntervalSizeable (diff, duration),
Intervallic (..), after,
before, begin, beginerval,
beginervalFromEnd, bi,
concur, contains,
disjoint, during,
enclosedBy, encloses, end,
enderval,
endervalFromBegin, equals,
extenterval, finishedBy,
finishes, meets, metBy,
notDisjoint, overlappedBy,
overlaps, relate,
startedBy, starts, within,
(<|>))
import safe IntervalAlgebra.PairedInterval (PairedInterval,
equalPairData,
getPairData,
makePairedInterval)
import safe Safe (headMay, initSafe,
lastMay, tailSafe)
import safe Witherable (Filterable (filter),
Witherable (..),
catMaybes, mapMaybe)
makeFolder :: (Monoid (m b), Applicative m) => (a -> a -> b) -> L.Fold a (m b)
makeFolder :: forall (m :: * -> *) b a.
(Monoid (m b), Applicative m) =>
(a -> a -> b) -> Fold a (m b)
makeFolder a -> a -> b
f = forall a b x. (x -> a -> x) -> x -> (x -> b) -> Fold a b
L.Fold forall {f :: * -> *}.
(Semigroup (f b), Applicative f) =>
(f b, Maybe a) -> a -> (f b, Maybe a)
step forall {a}. (m b, Maybe a)
begin forall {a} {b}. (a, b) -> a
done
where
begin :: (m b, Maybe a)
begin = (forall a. Monoid a => a
mempty, forall a. Maybe a
Nothing)
step :: (f b, Maybe a) -> a -> (f b, Maybe a)
step (f b
fs, Maybe a
Nothing) a
y = (f b
fs, forall a. a -> Maybe a
Just a
y)
step (f b
fs, Just a
x ) a
y = (f b
fs forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> a -> b
f a
x a
y), forall a. a -> Maybe a
Just a
y)
done :: (a, b) -> a
done (a
fs, b
_) = a
fs
makeGapsWithinPredicate
:: ( Monoid (t (Interval a))
, Monoid (t (Maybe (Interval a)))
, Applicative t
, Witherable.Witherable t
, IntervalSizeable a b
, Intervallic i0
, IntervalCombinable i1 a
)
=> ((b -> Bool) -> t b -> Bool)
-> (b -> b -> Bool)
-> (b -> i0 a -> t (i1 a) -> Bool)
makeGapsWithinPredicate :: forall (t :: * -> *) a b (i0 :: * -> *) (i1 :: * -> *).
(Monoid (t (Interval a)), Monoid (t (Maybe (Interval a))),
Applicative t, Witherable t, IntervalSizeable a b, Intervallic i0,
IntervalCombinable i1 a) =>
((b -> Bool) -> t b -> Bool)
-> (b -> b -> Bool) -> b -> i0 a -> t (i1 a) -> Bool
makeGapsWithinPredicate (b -> Bool) -> t b -> Bool
f b -> b -> Bool
op b
gapDuration i0 a
interval t (i1 a)
l =
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False ((b -> Bool) -> t b -> Bool
f (b -> b -> Bool
`op` b
gapDuration) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (i :: * -> *) a b.
(Functor f, Intervallic i, IntervalSizeable a b) =>
f (i a) -> f b
durations) (forall (f :: * -> *) a b (i0 :: * -> *) (i1 :: * -> *).
(Applicative f, Witherable f, Monoid (f (Interval a)),
Monoid (f (Maybe (Interval a))), IntervalSizeable a b,
Intervallic i0, IntervalCombinable i1 a) =>
i0 a -> f (i1 a) -> Maybe (f (Interval a))
gapsWithin i0 a
interval t (i1 a)
l)
pairGaps
:: (Intervallic i, IntervalSizeable a b, IntervalCombinable i a)
=> [i a]
-> [Maybe b]
pairGaps :: forall (i :: * -> *) a b.
(Intervallic i, IntervalSizeable a b, IntervalCombinable i a) =>
[i a] -> [Maybe b]
pairGaps [i a]
es = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b (i :: * -> *).
(IntervalSizeable a b, Intervallic i) =>
i a -> b
duration forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (i :: * -> *) a.
IntervalCombinable i a =>
i a -> i a -> Maybe (i a)
(><)) (forall {a}. [a] -> [(a, a)]
pairs [i a]
es)
where
pairs :: [a] -> [(a, a)]
pairs = forall {a}. [a] -> [(a, a)]
go
where
go :: [a] -> [(a, a)]
go [] = []
go (a
x : [a]
xs) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
x, ) [a]
xs forall a. Semigroup a => a -> a -> a
<> [a] -> [(a, a)]
go [a]
xs
lookback
:: (Intervallic i, IntervalSizeable a b)
=> b
-> i a
-> Interval a
lookback :: forall (i :: * -> *) a b.
(Intervallic i, IntervalSizeable a b) =>
b -> i a -> Interval a
lookback b
d i a
x = forall a b. IntervalSizeable a b => b -> a -> Interval a
enderval b
d (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i a
x)
lookahead
:: (Intervallic i, IntervalSizeable a b)
=> b
-> i a
-> Interval a
lookahead :: forall (i :: * -> *) a b.
(Intervallic i, IntervalSizeable a b) =>
b -> i a -> Interval a
lookahead b
d i a
x = forall a b. IntervalSizeable a b => b -> a -> Interval a
beginerval b
d (forall (i :: * -> *) a. Intervallic i => i a -> a
end i a
x)
anyGapsWithinAtLeastDuration
:: ( IntervalSizeable a b
, Intervallic i0
, IntervalCombinable i1 a
, Monoid (t (Interval a))
, Monoid (t (Maybe (Interval a)))
, Applicative t
, Witherable.Witherable t
)
=> b
-> i0 a
-> t (i1 a)
-> Bool
anyGapsWithinAtLeastDuration :: forall a b (i0 :: * -> *) (i1 :: * -> *) (t :: * -> *).
(IntervalSizeable a b, Intervallic i0, IntervalCombinable i1 a,
Monoid (t (Interval a)), Monoid (t (Maybe (Interval a))),
Applicative t, Witherable t) =>
b -> i0 a -> t (i1 a) -> Bool
anyGapsWithinAtLeastDuration = forall (t :: * -> *) a b (i0 :: * -> *) (i1 :: * -> *).
(Monoid (t (Interval a)), Monoid (t (Maybe (Interval a))),
Applicative t, Witherable t, IntervalSizeable a b, Intervallic i0,
IntervalCombinable i1 a) =>
((b -> Bool) -> t b -> Bool)
-> (b -> b -> Bool) -> b -> i0 a -> t (i1 a) -> Bool
makeGapsWithinPredicate forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any forall a. Ord a => a -> a -> Bool
(>=)
allGapsWithinLessThanDuration
:: ( IntervalSizeable a b
, Intervallic i0
, IntervalCombinable i1 a
, Monoid (t (Interval a))
, Monoid (t (Maybe (Interval a)))
, Applicative t
, Witherable.Witherable t
)
=> b
-> i0 a
-> t (i1 a)
-> Bool
allGapsWithinLessThanDuration :: forall a b (i0 :: * -> *) (i1 :: * -> *) (t :: * -> *).
(IntervalSizeable a b, Intervallic i0, IntervalCombinable i1 a,
Monoid (t (Interval a)), Monoid (t (Maybe (Interval a))),
Applicative t, Witherable t) =>
b -> i0 a -> t (i1 a) -> Bool
allGapsWithinLessThanDuration = forall (t :: * -> *) a b (i0 :: * -> *) (i1 :: * -> *).
(Monoid (t (Interval a)), Monoid (t (Maybe (Interval a))),
Applicative t, Witherable t, IntervalSizeable a b, Intervallic i0,
IntervalCombinable i1 a) =>
((b -> Bool) -> t b -> Bool)
-> (b -> b -> Bool) -> b -> i0 a -> t (i1 a) -> Bool
makeGapsWithinPredicate forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall a. Ord a => a -> a -> Bool
(<)
listCombiner
:: (Maybe a -> Maybe a -> [a])
-> [a]
-> [a]
-> [a]
listCombiner :: forall a. (Maybe a -> Maybe a -> [a]) -> [a] -> [a] -> [a]
listCombiner Maybe a -> Maybe a -> [a]
f [a]
x [a]
y = forall a. [a] -> [a]
initSafe [a]
x forall a. Semigroup a => a -> a -> a
<> Maybe a -> Maybe a -> [a]
f (forall a. [a] -> Maybe a
lastMay [a]
x) (forall a. [a] -> Maybe a
headMay [a]
y) forall a. Semigroup a => a -> a -> a
<> forall a. [a] -> [a]
tailSafe [a]
y
{-# INLINABLE listCombiner #-}
relationsL
:: (Foldable f, Ord a, Intervallic i) => f (i a) -> [IntervalRelation]
relationsL :: forall (f :: * -> *) a (i :: * -> *).
(Foldable f, Ord a, Intervallic i) =>
f (i a) -> [IntervalRelation]
relationsL = forall (f :: * -> *) (m :: * -> *) a (i :: * -> *).
(Foldable f, Applicative m, Ord a, Intervallic i,
Monoid (m IntervalRelation)) =>
f (i a) -> m IntervalRelation
relations
relations
:: ( Foldable f
, Applicative m
, Ord a
, Intervallic i
, Monoid (m IntervalRelation)
)
=> f (i a)
-> m IntervalRelation
relations :: forall (f :: * -> *) (m :: * -> *) a (i :: * -> *).
(Foldable f, Applicative m, Ord a, Intervallic i,
Monoid (m IntervalRelation)) =>
f (i a) -> m IntervalRelation
relations = forall (f :: * -> *) a b. Foldable f => Fold a b -> f a -> b
L.fold (forall (m :: * -> *) b a.
(Monoid (m b), Applicative m) =>
(a -> a -> b) -> Fold a (m b)
makeFolder forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> i1 a -> IntervalRelation
relate)
{-# INLINABLE relations #-}
intersect
:: (Intervallic i, IntervalSizeable a b) => i a -> i a -> Maybe (Interval a)
intersect :: forall (i :: * -> *) a b.
(Intervallic i, IntervalSizeable a b) =>
i a -> i a -> Maybe (Interval a)
intersect i a
x i a
y | forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
disjoint i a
x i a
y = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. IntervalSizeable a b => b -> a -> Interval a
beginerval (forall a b. IntervalSizeable a b => a -> a -> b
diff a
e a
b) a
b
where
b :: a
b = forall a. Ord a => a -> a -> a
max (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i a
x) (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i a
y)
e :: a
e = forall a. Ord a => a -> a -> a
min (forall (i :: * -> *) a. Intervallic i => i a -> a
end i a
x) (forall (i :: * -> *) a. Intervallic i => i a -> a
end i a
y)
gapsM
:: ( IntervalCombinable i a
, Traversable f
, Monoid (f (Maybe (Interval a)))
, Applicative f
)
=> f (i a)
-> f (Maybe (Interval a))
gapsM :: forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Traversable f,
Monoid (f (Maybe (Interval a))), Applicative f) =>
f (i a) -> f (Maybe (Interval a))
gapsM = forall (f :: * -> *) a b. Foldable f => Fold a b -> f a -> b
L.fold (forall (m :: * -> *) b a.
(Monoid (m b), Applicative m) =>
(a -> a -> b) -> Fold a (m b)
makeFolder (\i a
i i a
j -> forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i a
i forall (i :: * -> *) a.
IntervalCombinable i a =>
i a -> i a -> Maybe (i a)
>< forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i a
j))
{-# INLINABLE gapsM #-}
gaps
:: ( IntervalCombinable i a
, Traversable f
, Monoid (f (Maybe (Interval a)))
, Applicative f
)
=> f (i a)
-> Maybe (f (Interval a))
gaps :: forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Traversable f,
Monoid (f (Maybe (Interval a))), Applicative f) =>
f (i a) -> Maybe (f (Interval a))
gaps = forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Traversable f,
Monoid (f (Maybe (Interval a))), Applicative f) =>
f (i a) -> f (Maybe (Interval a))
gapsM
{-# INLINABLE gaps #-}
gapsL
:: ( IntervalCombinable i a
, Applicative f
, Monoid (f (Maybe (Interval a)))
, Traversable f
)
=> f (i a)
-> [Interval a]
gapsL :: forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Applicative f,
Monoid (f (Maybe (Interval a))), Traversable f) =>
f (i a) -> [Interval a]
gapsL f (i a)
x = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Traversable f,
Monoid (f (Maybe (Interval a))), Applicative f) =>
f (i a) -> Maybe (f (Interval a))
gaps f (i a)
x)
{-# INLINABLE gapsL #-}
durations :: (Functor f, Intervallic i, IntervalSizeable a b) => f (i a) -> f b
durations :: forall (f :: * -> *) (i :: * -> *) a b.
(Functor f, Intervallic i, IntervalSizeable a b) =>
f (i a) -> f b
durations = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b (i :: * -> *).
(IntervalSizeable a b, Intervallic i) =>
i a -> b
duration
clip
:: (Intervallic i0, Intervallic i1, IntervalSizeable a b)
=> i0 a
-> i1 a
-> Maybe (Interval a)
clip :: forall (i0 :: * -> *) (i1 :: * -> *) a b.
(Intervallic i0, Intervallic i1, IntervalSizeable a b) =>
i0 a -> i1 a -> Maybe (Interval a)
clip i0 a
x i1 a
y
| forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlaps i0 a
x i1 a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. IntervalSizeable a b => b -> a -> Interval a
enderval (forall a b. IntervalSizeable a b => a -> a -> b
diff (forall (i :: * -> *) a. Intervallic i => i a -> a
end i0 a
x) (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i1 a
y)) (forall (i :: * -> *) a. Intervallic i => i a -> a
end i0 a
x)
| forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlappedBy i0 a
x i1 a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a b. IntervalSizeable a b => b -> a -> Interval a
beginerval (forall a b. IntervalSizeable a b => a -> a -> b
diff (forall (i :: * -> *) a. Intervallic i => i a -> a
end i1 a
y) (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i0 a
x)) (forall (i :: * -> *) a. Intervallic i => i a -> a
begin i0 a
x)
| ComparativePredicateOf2 (i0 a) (i1 a)
jx i0 a
x i1 a
y = forall a. a -> Maybe a
Just (forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i0 a
x)
| ComparativePredicateOf2 (i0 a) (i1 a)
jy i0 a
x i1 a
y = forall a. a -> Maybe a
Just (forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i1 a
y)
| Bool
otherwise = forall a. Maybe a
Nothing
where
jy :: ComparativePredicateOf2 (i0 a) (i1 a)
jy = forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
equals forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
startedBy forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
contains forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishedBy
jx :: ComparativePredicateOf2 (i0 a) (i1 a)
jx = forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
starts forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
during forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishes
{-# INLINABLE clip #-}
gapsWithin
:: ( Applicative f
, Witherable f
, Monoid (f (Interval a))
, Monoid (f (Maybe (Interval a)))
, IntervalSizeable a b
, Intervallic i0
, IntervalCombinable i1 a
)
=> i0 a
-> f (i1 a)
-> Maybe (f (Interval a))
gapsWithin :: forall (f :: * -> *) a b (i0 :: * -> *) (i1 :: * -> *).
(Applicative f, Witherable f, Monoid (f (Interval a)),
Monoid (f (Maybe (Interval a))), IntervalSizeable a b,
Intervallic i0, IntervalCombinable i1 a) =>
i0 a -> f (i1 a) -> Maybe (f (Interval a))
gapsWithin i0 a
i f (i1 a)
x | forall (t :: * -> *) a. Foldable t => t a -> Bool
null f (Interval a)
ivs = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just f (Interval a)
res
where
s :: f (Interval a)
s = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b (i :: * -> *).
(IntervalSizeable a b, Intervallic i) =>
b -> i a -> Interval a
endervalFromBegin b
0 i0 a
i)
e :: f (Interval a)
e = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b (i :: * -> *).
(IntervalSizeable a b, Intervallic i) =>
b -> i a -> Interval a
beginervalFromEnd b
0 i0 a
i)
ivs :: f (Interval a)
ivs = forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (forall (i0 :: * -> *) (i1 :: * -> *) a b.
(Intervallic i0, Intervallic i1, IntervalSizeable a b) =>
i0 a -> i1 a -> Maybe (Interval a)
clip i0 a
i) (forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterNotDisjoint i0 a
i f (i1 a)
x)
res :: f (Interval a)
res = forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes forall a b. (a -> b) -> a -> b
$ forall (i :: * -> *) a (f :: * -> *).
(IntervalCombinable i a, Traversable f,
Monoid (f (Maybe (Interval a))), Applicative f) =>
f (i a) -> f (Maybe (Interval a))
gapsM (f (Interval a)
s forall a. Semigroup a => a -> a -> a
<> f (Interval a)
ivs forall a. Semigroup a => a -> a -> a
<> f (Interval a)
e)
{-# INLINABLE gapsWithin #-}
combineIntervals
:: (Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)), Foldable f)
=> f (i a)
-> f (Interval a)
combineIntervals :: forall (f :: * -> *) a (i :: * -> *).
(Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)),
Foldable f) =>
f (i a) -> f (Interval a)
combineIntervals = forall (f :: * -> *) a (i :: * -> *).
(Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)),
Foldable f) =>
([i a] -> [Interval a]) -> f (i a) -> f (Interval a)
combineIntervalsWith forall (i :: * -> *) a.
(Intervallic i, Ord a) =>
[i a] -> [Interval a]
combineIntervalsL
combineIntervalsFromSorted
:: (Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)), Foldable f)
=> f (i a)
-> f (Interval a)
combineIntervalsFromSorted :: forall (f :: * -> *) a (i :: * -> *).
(Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)),
Foldable f) =>
f (i a) -> f (Interval a)
combineIntervalsFromSorted = forall (f :: * -> *) a (i :: * -> *).
(Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)),
Foldable f) =>
([i a] -> [Interval a]) -> f (i a) -> f (Interval a)
combineIntervalsWith forall a (i :: * -> *).
(Ord a, Intervallic i) =>
[i a] -> [Interval a]
combineIntervalsFromSortedL
combineIntervalsWith
:: (Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)), Foldable f)
=> ([i a] -> [Interval a])
-> f (i a)
-> f (Interval a)
combineIntervalsWith :: forall (f :: * -> *) a (i :: * -> *).
(Applicative f, Ord a, Intervallic i, Monoid (f (Interval a)),
Foldable f) =>
([i a] -> [Interval a]) -> f (i a) -> f (Interval a)
combineIntervalsWith [i a] -> [Interval a]
f f (i a)
x = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\f (Interval a)
x Interval a
y -> f (Interval a)
x forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure Interval a
y) forall a. Monoid a => a
mempty ([i a] -> [Interval a]
f forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f (i a)
x)
combineIntervalsL :: (Intervallic i, Ord a) => [i a] -> [Interval a]
combineIntervalsL :: forall (i :: * -> *) a.
(Intervallic i, Ord a) =>
[i a] -> [Interval a]
combineIntervalsL = forall a (i :: * -> *).
(Ord a, Intervallic i) =>
[i a] -> [Interval a]
combineIntervalsFromSortedL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval
combineIntervalsFromSortedL
:: forall a i . (Ord a, Intervallic i) => [i a] -> [Interval a]
combineIntervalsFromSortedL :: forall a (i :: * -> *).
(Ord a, Intervallic i) =>
[i a] -> [Interval a]
combineIntervalsFromSortedL = forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall {i1 :: * -> *} {a}.
(Ord a, Intervallic i1) =>
[Interval a] -> i1 a -> [Interval a]
op []
where
op :: [Interval a] -> i1 a -> [Interval a]
op [] i1 a
y = [forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i1 a
y]
op (Interval a
x : [Interval a]
xs) i1 a
y = if Interval a
x forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
`before` i1 a
y
then Interval a
yiv forall a. a -> [a] -> [a]
: Interval a
x forall a. a -> [a] -> [a]
: [Interval a]
xs
else forall a (i :: * -> *).
(Ord a, Intervallic i) =>
i a -> i a -> Interval a
extenterval Interval a
x Interval a
yiv forall a. a -> [a] -> [a]
: [Interval a]
xs
where yiv :: Interval a
yiv = forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval i1 a
y
rangeInterval :: (Ord a, L.Foldable t) => t (Interval a) -> Maybe (Interval a)
rangeInterval :: forall a (t :: * -> *).
(Ord a, Foldable t) =>
t (Interval a) -> Maybe (Interval a)
rangeInterval = forall (f :: * -> *) a b. Foldable f => Fold a b -> f a -> b
L.fold (forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a (i :: * -> *).
(Ord a, Intervallic i) =>
i a -> i a -> Interval a
extenterval forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Ord a => Fold a (Maybe a)
L.minimum forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Ord a => Fold a (Maybe a)
L.maximum)
nothingIf
:: (Monoid (f (i a)), Filterable f)
=> ((i a -> Bool) -> f (i a) -> Bool)
-> (i a -> Bool)
-> f (i a)
-> Maybe (f (i a))
nothingIf :: forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Filterable f) =>
((i a -> Bool) -> f (i a) -> Bool)
-> (i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIf (i a -> Bool) -> f (i a) -> Bool
quantifier i a -> Bool
predicate f (i a)
x =
if (i a -> Bool) -> f (i a) -> Bool
quantifier i a -> Bool
predicate f (i a)
x then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just f (i a)
x
nothingIfNone
:: (Monoid (f (i a)), Foldable f, Filterable f)
=> (i a -> Bool)
-> f (i a)
-> Maybe (f (i a))
nothingIfNone :: forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Foldable f, Filterable f) =>
(i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIfNone = forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Filterable f) =>
((i a -> Bool) -> f (i a) -> Bool)
-> (i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIf (\i a -> Bool
f f (i a)
x -> (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any i a -> Bool
f) f (i a)
x)
nothingIfAny
:: (Monoid (f (i a)), Foldable f, Filterable f)
=> (i a -> Bool)
-> f (i a)
-> Maybe (f (i a))
nothingIfAny :: forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Foldable f, Filterable f) =>
(i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIfAny = forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Filterable f) =>
((i a -> Bool) -> f (i a) -> Bool)
-> (i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIf forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
nothingIfAll
:: (Monoid (f (i a)), Foldable f, Filterable f)
=> (i a -> Bool)
-> f (i a)
-> Maybe (f (i a))
nothingIfAll :: forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Foldable f, Filterable f) =>
(i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIfAll = forall (f :: * -> *) (i :: * -> *) a.
(Monoid (f (i a)), Filterable f) =>
((i a -> Bool) -> f (i a) -> Bool)
-> (i a -> Bool) -> f (i a) -> Maybe (f (i a))
nothingIf forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all
makeFilter
:: (Filterable f, Intervallic i0, Intervallic i1)
=> ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a
-> (f (i1 a) -> f (i1 a))
makeFilter :: forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter ComparativePredicateOf2 (i0 a) (i1 a)
f i0 a
p = forall (f :: * -> *) a. Filterable f => (a -> Bool) -> f a -> f a
Witherable.filter (ComparativePredicateOf2 (i0 a) (i1 a)
f i0 a
p)
filterOverlaps, filterOverlappedBy, filterBefore, filterAfter, filterStarts, filterStartedBy, filterFinishes, filterFinishedBy, filterMeets, filterMetBy, filterDuring, filterContains, filterEquals, filterDisjoint, filterNotDisjoint, filterConcur, filterWithin, filterEncloses, filterEnclosedBy
:: (Filterable f, Ord a, Intervallic i0, Intervallic i1)
=> i0 a
-> f (i1 a)
-> f (i1 a)
filterOverlaps :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterOverlaps = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlaps
filterOverlappedBy :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterOverlappedBy = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
overlappedBy
filterBefore :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterBefore = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
before
filterAfter :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterAfter = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
after
filterStarts :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterStarts = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
starts
filterStartedBy :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterStartedBy = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
startedBy
filterFinishes :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterFinishes = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishes
filterFinishedBy :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterFinishedBy = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
finishedBy
filterMeets :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterMeets = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Eq a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
meets
filterMetBy :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterMetBy = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Eq a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
metBy
filterDuring :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterDuring = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
during
filterContains :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterContains = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
contains
filterEquals :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterEquals = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
equals
filterDisjoint :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterDisjoint = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
disjoint
filterNotDisjoint :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterNotDisjoint = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
notDisjoint
filterConcur :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterConcur = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
concur
filterWithin :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterWithin = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
within
filterEncloses :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterEncloses = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
encloses
filterEnclosedBy :: forall (f :: * -> *) a (i0 :: * -> *) (i1 :: * -> *).
(Filterable f, Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> f (i1 a) -> f (i1 a)
filterEnclosedBy = forall (f :: * -> *) (i0 :: * -> *) (i1 :: * -> *) a.
(Filterable f, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> i0 a -> f (i1 a) -> f (i1 a)
makeFilter forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
enclosedBy
foldMeetingSafe
:: (Eq b, Ord a, Show a)
=> [PairedInterval b a]
-> [PairedInterval b a]
foldMeetingSafe :: forall b a.
(Eq b, Ord a, Show a) =>
[PairedInterval b a] -> [PairedInterval b a]
foldMeetingSafe [PairedInterval b a]
l = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (forall a. Meeting a -> a
getMeeting forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting) (forall a (i :: * -> *).
(Ord a, Intervallic i) =>
[i a] -> Maybe (Meeting [i a])
parseMeeting [PairedInterval b a]
l)
foldMeeting
:: (Eq b, Ord a, Show a)
=> Meeting [PairedInterval b a]
-> Meeting [PairedInterval b a]
foldMeeting :: forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting (Meeting [PairedInterval b a]
l) =
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a]
-> Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
joinMeetingPairedInterval (forall a. a -> Meeting a
Meeting []) (forall a. [a] -> [Meeting [a]]
packMeeting [PairedInterval b a]
l)
newtype Meeting a = Meeting { forall a. Meeting a -> a
getMeeting :: a } deriving (Meeting a -> Meeting a -> Bool
forall a. Eq a => Meeting a -> Meeting a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Meeting a -> Meeting a -> Bool
$c/= :: forall a. Eq a => Meeting a -> Meeting a -> Bool
== :: Meeting a -> Meeting a -> Bool
$c== :: forall a. Eq a => Meeting a -> Meeting a -> Bool
Eq, Int -> Meeting a -> ShowS
forall a. Show a => Int -> Meeting a -> ShowS
forall a. Show a => [Meeting a] -> ShowS
forall a. Show a => Meeting a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Meeting a] -> ShowS
$cshowList :: forall a. Show a => [Meeting a] -> ShowS
show :: Meeting a -> String
$cshow :: forall a. Show a => Meeting a -> String
showsPrec :: Int -> Meeting a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Meeting a -> ShowS
Show)
packMeeting :: [a] -> [Meeting [a]]
packMeeting :: forall a. [a] -> [Meeting [a]]
packMeeting = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
z -> forall a. a -> Meeting a
Meeting [a
z])
parseMeeting :: (Ord a, Intervallic i) => [i a] -> Maybe (Meeting [i a])
parseMeeting :: forall a (i :: * -> *).
(Ord a, Intervallic i) =>
[i a] -> Maybe (Meeting [i a])
parseMeeting [i a]
x | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== IntervalRelation
Meets) (forall (f :: * -> *) a (i :: * -> *).
(Foldable f, Ord a, Intervallic i) =>
f (i a) -> [IntervalRelation]
relationsL [i a]
x) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [i a]
x
| Bool
otherwise = forall a. Maybe a
Nothing
joinMeetingPairedInterval
:: (Eq b, Ord a, Show a)
=> Meeting [PairedInterval b a]
-> Meeting [PairedInterval b a]
-> Meeting [PairedInterval b a]
joinMeetingPairedInterval :: forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a]
-> Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
joinMeetingPairedInterval = forall a (i :: * -> *).
(Ord a, Intervallic i) =>
ComparativePredicateOf1 (i a)
-> Meeting [i a] -> Meeting [i a] -> Meeting [i a]
joinMeeting forall b a. Eq b => ComparativePredicateOf1 (PairedInterval b a)
equalPairData
joinMeeting
:: (Ord a, Intervallic i)
=> ComparativePredicateOf1 (i a)
-> Meeting [i a]
-> Meeting [i a]
-> Meeting [i a]
joinMeeting :: forall a (i :: * -> *).
(Ord a, Intervallic i) =>
ComparativePredicateOf1 (i a)
-> Meeting [i a] -> Meeting [i a] -> Meeting [i a]
joinMeeting ComparativePredicateOf1 (i a)
f (Meeting [i a]
x) (Meeting [i a]
y) =
forall a. a -> Meeting a
Meeting forall a b. (a -> b) -> a -> b
$ forall a. (Maybe a -> Maybe a -> [a]) -> [a] -> [a] -> [a]
listCombiner (forall a (i :: * -> *).
(Ord a, Intervallic i) =>
ComparativePredicateOf1 (i a)
-> Maybe (i a) -> Maybe (i a) -> [i a]
join2MeetingWhen ComparativePredicateOf1 (i a)
f) [i a]
x [i a]
y
join2MeetingWhen
:: (Ord a, Intervallic i)
=> ComparativePredicateOf1 (i a)
-> Maybe (i a)
-> Maybe (i a)
-> [i a]
join2MeetingWhen :: forall a (i :: * -> *).
(Ord a, Intervallic i) =>
ComparativePredicateOf1 (i a)
-> Maybe (i a) -> Maybe (i a) -> [i a]
join2MeetingWhen ComparativePredicateOf1 (i a)
p Maybe (i a)
Nothing Maybe (i a)
Nothing = []
join2MeetingWhen ComparativePredicateOf1 (i a)
p Maybe (i a)
Nothing (Just i a
y) = [i a
y]
join2MeetingWhen ComparativePredicateOf1 (i a)
p (Just i a
x) Maybe (i a)
Nothing = [i a
x]
join2MeetingWhen ComparativePredicateOf1 (i a)
p (Just i a
x) (Just i a
y) | ComparativePredicateOf1 (i a)
p i a
x i a
y = [forall (i :: * -> *) a b. Intervallic i => i a -> Interval b -> i b
setInterval i a
y (forall a (i :: * -> *).
(Ord a, Intervallic i) =>
i a -> i a -> Interval a
extenterval i a
x i a
y)]
| Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure i a
x forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure i a
y
disjoinPaired
:: (Eq b, Monoid b, Show a, IntervalSizeable a c)
=> (PairedInterval b) a
-> (PairedInterval b) a
-> Meeting [(PairedInterval b) a]
disjoinPaired :: forall b a c.
(Eq b, Monoid b, Show a, IntervalSizeable a c) =>
PairedInterval b a
-> PairedInterval b a -> Meeting [PairedInterval b a]
disjoinPaired PairedInterval b a
o PairedInterval b a
e = case forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
i0 a -> i1 a -> IntervalRelation
relate PairedInterval b a
x PairedInterval b a
y of
IntervalRelation
Before -> forall a. a -> Meeting a
Meeting [PairedInterval b a
x, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
e1 a
b2 forall a. Monoid a => a
mempty, PairedInterval b a
y]
IntervalRelation
Meets -> forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [PairedInterval b a
x, PairedInterval b a
y]
IntervalRelation
Overlaps -> forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
b1 a
b2 b
s1, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
b2 a
e1 b
sc, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
e1 a
e2 b
s2]
IntervalRelation
FinishedBy -> forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
b1 a
b2 b
s1, forall {a} {a}. Interval a -> a -> PairedInterval a a
ev Interval a
i2 b
sc]
IntervalRelation
Contains -> forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
b1 a
b2 b
s1, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
b2 a
e2 b
sc, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
e2 a
e1 b
s1]
IntervalRelation
Starts -> forall b a.
(Eq b, Ord a, Show a) =>
Meeting [PairedInterval b a] -> Meeting [PairedInterval b a]
foldMeeting forall a b. (a -> b) -> a -> b
$ forall a. a -> Meeting a
Meeting [forall {a} {a}. Interval a -> a -> PairedInterval a a
ev Interval a
i1 b
sc, forall {a} {b} {a}.
IntervalSizeable a b =>
a -> a -> a -> PairedInterval a a
evp a
e1 a
e2 b
s2]
IntervalRelation
_ -> forall a. a -> Meeting a
Meeting [forall {a} {a}. Interval a -> a -> PairedInterval a a
ev Interval a
i1 b
sc]
where
x :: PairedInterval b a
x = forall a. Ord a => a -> a -> a
min PairedInterval b a
o PairedInterval b a
e
y :: PairedInterval b a
y = forall a. Ord a => a -> a -> a
max PairedInterval b a
o PairedInterval b a
e
i1 :: Interval a
i1 = forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval PairedInterval b a
x
i2 :: Interval a
i2 = forall (i :: * -> *) a. Intervallic i => i a -> Interval a
getInterval PairedInterval b a
y
s1 :: b
s1 = forall b a. PairedInterval b a -> b
getPairData PairedInterval b a
x
s2 :: b
s2 = forall b a. PairedInterval b a -> b
getPairData PairedInterval b a
y
sc :: b
sc = b
s1 forall a. Semigroup a => a -> a -> a
<> b
s2
b1 :: a
b1 = forall (i :: * -> *) a. Intervallic i => i a -> a
begin PairedInterval b a
x
b2 :: a
b2 = forall (i :: * -> *) a. Intervallic i => i a -> a
begin PairedInterval b a
y
e1 :: a
e1 = forall (i :: * -> *) a. Intervallic i => i a -> a
end PairedInterval b a
x
e2 :: a
e2 = forall (i :: * -> *) a. Intervallic i => i a -> a
end PairedInterval b a
y
ev :: Interval a -> a -> PairedInterval a a
ev = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b a. b -> Interval a -> PairedInterval b a
makePairedInterval
evp :: a -> a -> a -> PairedInterval a a
evp a
b a
e = forall {a} {a}. Interval a -> a -> PairedInterval a a
ev (forall a b. IntervalSizeable a b => b -> a -> Interval a
beginerval (forall a b. IntervalSizeable a b => a -> a -> b
diff a
e a
b) a
b)
{-# INLINABLE disjoinPaired #-}
recurseDisjoin
:: (Monoid b, Eq b, IntervalSizeable a c, Show a)
=> ([(PairedInterval b) a], [(PairedInterval b) a])
-> [(PairedInterval b) a]
-> [(PairedInterval b) a]
recurseDisjoin :: forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([PairedInterval b a]
acc, PairedInterval b a
o : [PairedInterval b a]
os) [] = [PairedInterval b a]
acc forall a. Semigroup a => a -> a -> a
<> (PairedInterval b a
o forall a. a -> [a] -> [a]
: [PairedInterval b a]
os)
recurseDisjoin ([PairedInterval b a]
acc, [] ) [] = [PairedInterval b a]
acc
recurseDisjoin ([PairedInterval b a]
acc, [] ) (PairedInterval b a
e : [PairedInterval b a]
es) = forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([PairedInterval b a]
acc, [PairedInterval b a
e]) [PairedInterval b a]
es
recurseDisjoin ([PairedInterval b a]
acc, PairedInterval b a
o : [PairedInterval b a]
os) (PairedInterval b a
e : [PairedInterval b a]
es)
|
PairedInterval b a
e forall a. Eq a => a -> a -> Bool
== PairedInterval b a
o = forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([PairedInterval b a]
acc, PairedInterval b a
o forall a. a -> [a] -> [a]
: [PairedInterval b a]
os) [PairedInterval b a]
es
|
(forall a (i0 :: * -> *) (i1 :: * -> *).
(Ord a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
before forall (i0 :: * -> *) (i1 :: * -> *) a.
(Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
-> ComparativePredicateOf2 (i0 a) (i1 a)
<|> forall a (i0 :: * -> *) (i1 :: * -> *).
(Eq a, Intervallic i0, Intervallic i1) =>
ComparativePredicateOf2 (i0 a) (i1 a)
meets) PairedInterval b a
o PairedInterval b a
e = forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin
([PairedInterval b a]
acc forall a. Semigroup a => a -> a -> a
<> [PairedInterval b a]
nh, forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([], [PairedInterval b a]
nt) [PairedInterval b a]
os)
[PairedInterval b a]
es
|
Bool
otherwise = forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([PairedInterval b a]
acc, forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([], [PairedInterval b a]
n) [PairedInterval b a]
os) [PairedInterval b a]
es
where
n :: [PairedInterval b a]
n = forall a. Meeting a -> a
getMeeting forall a b. (a -> b) -> a -> b
$ forall b a c.
(Eq b, Monoid b, Show a, IntervalSizeable a c) =>
PairedInterval b a
-> PairedInterval b a -> Meeting [PairedInterval b a]
disjoinPaired PairedInterval b a
o PairedInterval b a
e
nh :: [PairedInterval b a]
nh = forall a. Maybe a -> [a]
maybeToList (forall a. [a] -> Maybe a
headMay [PairedInterval b a]
n)
nt :: [PairedInterval b a]
nt = forall a. [a] -> [a]
tailSafe [PairedInterval b a]
n
{-# INLINABLE recurseDisjoin #-}
formMeetingSequence
:: (Eq b, Show a, Monoid b, IntervalSizeable a c)
=> [PairedInterval b a]
-> [PairedInterval b a]
formMeetingSequence :: forall b a c.
(Eq b, Show a, Monoid b, IntervalSizeable a c) =>
[PairedInterval b a] -> [PairedInterval b a]
formMeetingSequence [PairedInterval b a]
x
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PairedInterval b a]
x = []
| forall a b. Ord a => [PairedInterval b a] -> Bool
allMeet [PairedInterval b a]
x Bool -> Bool -> Bool
&& Bool -> Bool
not (forall b a. Eq b => [PairedInterval b a] -> Bool
hasEqData [PairedInterval b a]
x) = [PairedInterval b a]
x
| Bool
otherwise = forall b a c.
(Eq b, Show a, Monoid b, IntervalSizeable a c) =>
[PairedInterval b a] -> [PairedInterval b a]
formMeetingSequence (forall b a c.
(Monoid b, Eq b, IntervalSizeable a c, Show a) =>
([PairedInterval b a], [PairedInterval b a])
-> [PairedInterval b a] -> [PairedInterval b a]
recurseDisjoin ([], []) [PairedInterval b a]
x)
{-# INLINABLE formMeetingSequence #-}
allMeet :: (Ord a) => [PairedInterval b a] -> Bool
allMeet :: forall a b. Ord a => [PairedInterval b a] -> Bool
allMeet [PairedInterval b a]
x = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== IntervalRelation
Meets) (forall (f :: * -> *) a (i :: * -> *).
(Foldable f, Ord a, Intervallic i) =>
f (i a) -> [IntervalRelation]
relationsL [PairedInterval b a]
x)
hasEqData :: (Eq b) => [PairedInterval b a] -> Bool
hasEqData :: forall b a. Eq b => [PairedInterval b a] -> Bool
hasEqData [PairedInterval b a]
x = forall (t :: * -> *). Foldable t => t Bool -> Bool
or (forall (f :: * -> *) a b. Foldable f => Fold a b -> f a -> b
L.fold (forall (m :: * -> *) b a.
(Monoid (m b), Applicative m) =>
(a -> a -> b) -> Fold a (m b)
makeFolder forall a. Eq a => a -> a -> Bool
(==)) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b a. PairedInterval b a -> b
getPairData [PairedInterval b a]
x) :: [Bool])