mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Add Min and Max newtypes (#2011)
This commit is contained in:
parent
6cc5510dae
commit
8b04206a35
27
daml-foundations/daml-ghc/daml-stdlib-src/DA/Semigroup.daml
Normal file
27
daml-foundations/daml-ghc/daml-stdlib-src/DA/Semigroup.daml
Normal file
@ -0,0 +1,27 @@
|
||||
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
-- SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
daml 1.2
|
||||
module DA.Semigroup where
|
||||
|
||||
-- | Semigroup under `min`
|
||||
--
|
||||
-- ```
|
||||
-- > Min 23 <> Min 42
|
||||
-- Min 23
|
||||
-- ```
|
||||
newtype Min a = Min a deriving (Eq, Ord, Show)
|
||||
|
||||
instance Ord a => Semigroup (Min a) where
|
||||
Min a <> Min b = Min (min a b)
|
||||
|
||||
-- | Semigroup under `max`
|
||||
--
|
||||
-- ```
|
||||
-- > Max 23 <> Max 42
|
||||
-- Max 42
|
||||
-- ```
|
||||
newtype Max a = Max a deriving (Eq, Ord, Show)
|
||||
|
||||
instance Ord a => Semigroup (Max a) where
|
||||
Max a <> Max b = Max (max a b)
|
@ -41,6 +41,7 @@ import DA.Optional.Total
|
||||
import DA.Optional
|
||||
import DA.Random
|
||||
import DA.Record
|
||||
import DA.Semigroup
|
||||
import DA.Text
|
||||
import DA.TextMap
|
||||
import DA.Time
|
||||
|
11
daml-foundations/daml-ghc/tests/SemigroupTest.daml
Normal file
11
daml-foundations/daml-ghc/tests/SemigroupTest.daml
Normal file
@ -0,0 +1,11 @@
|
||||
-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates.
|
||||
-- All rights reserved.
|
||||
|
||||
daml 1.2
|
||||
module SemigroupTest where
|
||||
|
||||
import DA.Semigroup
|
||||
|
||||
test = scenario do
|
||||
assert $ Min (23 : Int) <> Min 42 == Min 23
|
||||
assert $ Max (23 : Int) <> Max 42 == Max 42
|
@ -24,6 +24,7 @@ import DA.NonEmpty()
|
||||
import DA.Optional()
|
||||
import DA.Random()
|
||||
import DA.Record()
|
||||
import DA.Semigroup()
|
||||
import DA.Text()
|
||||
import DA.Time()
|
||||
import DA.Traversable()
|
||||
|
@ -42,3 +42,5 @@ HEAD — ongoing
|
||||
- [DAML Standard Library] Add ``Sum`` and ``Product`` newtypes that
|
||||
provide ``Monoid`` instances based on the ``Additive`` and ``Multiplicative``
|
||||
instances of the underlying type.
|
||||
- [DAML Standard Library] Add ``Min`` and ``Max`` newtypes that
|
||||
provide ``Semigroup`` instances based ``min`` and ``max``.
|
||||
|
Loading…
Reference in New Issue
Block a user