{-# OPTIONS_GHC -Wno-orphans #-}

module Data.SegTree.RangeAddRangeMin where

import Data.SegTree
import Data.Semigroup

instance
  (Num a, Ord a, Bounded a) =>
  AsSemigroupEndo (Sum a) (Min a)
  where
  sendo :: Sum a -> Min a -> Min a
sendo (Sum a
x) (Min a
y)
    | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
forall a. Bounded a => a
maxBound = a -> Min a
forall a. a -> Min a
Min (a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y)
    | Bool
otherwise = a -> Min a
forall a. a -> Min a
Min a
forall a. Bounded a => a
maxBound
  {-# INLINE sendo #-}