Skip to content

Commit

Permalink
Use comparator field of Comparable.By atom
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jul 8, 2024
1 parent 280b7a7 commit e908a32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
27 changes: 9 additions & 18 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from project.Data.Boolean import Boolean, False, True
from project.Data.Ordering import all
from project.Data.Range.Extensions import all
from project.Function import const
from project.Internal.Ordering_Helpers import assert_same_comparators

## Any is the universal top-type, with all other types being subsumed by it.

Expand Down Expand Up @@ -195,8 +196,8 @@ type Any
a > 147
> : Any -> Boolean ! Incomparable_Values
> self that =
assert_same_comparators self that <|
case (Comparable.from self).compare self that of
assert_same_comparators self that comparator->
case comparator.compare self that of
Ordering.Greater -> True
Nothing -> Error.throw (Incomparable_Values.Error self that)
_ -> False
Expand Down Expand Up @@ -225,8 +226,8 @@ type Any
a >= 147
>= : Any -> Boolean ! Incomparable_Values
>= self that =
assert_same_comparators self that <|
case (Comparable.from self).compare self that of
assert_same_comparators self that comparator->
case comparator.compare self that of
Ordering.Equal -> True
Ordering.Greater -> True
Nothing -> Error.throw (Incomparable_Values.Error self that)
Expand Down Expand Up @@ -255,8 +256,8 @@ type Any
a < 147
< : Any -> Boolean ! Incomparable_Values
< self that =
assert_same_comparators self that <|
case (Comparable.from self).compare self that of
assert_same_comparators self that comparator->
case comparator.compare self that of
Ordering.Less -> True
Nothing -> Error.throw (Incomparable_Values.Error self that)
_ -> False
Expand Down Expand Up @@ -287,8 +288,8 @@ type Any
a < 147
<= : Any -> Boolean ! Incomparable_Values
<= self that =
assert_same_comparators self that <|
case (Comparable.from self).compare self that of
assert_same_comparators self that comparator->
case comparator.compare self that of
Ordering.Equal -> True
Ordering.Less -> True
Nothing -> Error.throw (Incomparable_Values.Error self that)
Expand Down Expand Up @@ -505,13 +506,3 @@ type Any
_ = warning_type
self

## PRIVATE
Checks if the comparators for the given objects are both of the same type. If so,
proceeds with the given action, and if not, throws `Incomparable_Values` error.
assert_same_comparators : Any -> Any -> (Any -> Any) -> Any ! Incomparable_Values
assert_same_comparators this that ~action =
comp_this = Comparable.from this
comp_that = Comparable.from that
case Meta.is_same_object comp_this comp_that of
True -> action
False -> Error.throw (Incomparable_Values.Error this that)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private

import project.Any.Any
from project.Data.Boolean import Boolean, False, True
from project.Data.Ordering import all
import project.Errors.Common.Incomparable_Values
import project.Error.Error
import project.Meta

## PRIVATE
Checks if the comparators for the given objects are both of the same type. If so,
proceeds with the given action, and if not, throws `Incomparable_Values` error.
assert_same_comparators : Any -> Any -> (Any -> Any) -> Any ! Incomparable_Values
assert_same_comparators this that ~action =
comp_this = Comparable.from this
comp_that = Comparable.from that
case Meta.is_same_object comp_this.comparator comp_that.comparator of
True -> action comp_this.comparator
False -> Error.throw (Incomparable_Values.Error this that)

0 comments on commit e908a32

Please sign in to comment.