1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Define unionRangesFrom with maybeConcat.

This commit is contained in:
Rob Rix 2016-03-04 20:07:52 -05:00
parent 2ca378db0d
commit 8325042643

View File

@ -69,8 +69,8 @@ unionRanges :: (Functor f, Foldable f) => f Range -> Range
unionRanges = unionRangesFrom (Range 0 0) unionRanges = unionRangesFrom (Range 0 0)
-- | Return a range that contains all the ranges in a Foldable, or the passed Range if the Foldable is empty. -- | Return a range that contains all the ranges in a Foldable, or the passed Range if the Foldable is empty.
unionRangesFrom :: (Functor f, Foldable f) => Range -> f Range -> Range unionRangesFrom :: Foldable f => Range -> f Range -> Range
unionRangesFrom range ranges = option range id . foldl mappend mempty $ Option . Just <$> ranges unionRangesFrom range = fromMaybe range . maybeConcat
-- | Return Just the union of all the ranges in a Foldable, or else Nothing. -- | Return Just the union of all the ranges in a Foldable, or else Nothing.
maybeUnionRanges :: Foldable f => f Range -> Maybe Range maybeUnionRanges :: Foldable f => f Range -> Maybe Range