From c8676cd36c31785112d47966baf33c3fc3f742b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Thu, 6 Oct 2022 19:57:40 +0200 Subject: [PATCH] cr: Made to_predicate a member --- .../0.0.0-dev/src/Data/Filter_Condition.enso | 47 +++++++++---------- .../Base/0.0.0-dev/src/Data/List.enso | 3 +- .../Base/0.0.0-dev/src/Data/Range.enso | 3 +- .../Base/0.0.0-dev/src/Data/Vector.enso | 3 +- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso index 281b8504c10d..2254cc1d10ce 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Filter_Condition.enso @@ -57,27 +57,26 @@ type Filter_Condition ## Is the value equal to False (Boolean only)? Is_False -## PRIVATE - Converts a `Filter_Condition` condition into a predicate taking an element - and returning a value indicating whether the element should be accepted by - the filter. -to_predicate filter_condition = case filter_condition of - Less value -> <=value - Equal value -> ==value - Equal_Or_Greater value -> >=value - Greater value -> >value - Not_Equal value -> !=value - Between lower upper -> elem -> - (lower <= elem) && (elem <= upper) - Starts_With prefix -> _.starts_with prefix - Ends_With suffix -> _.ends_with suffix - Contains substring -> _.contains substring - Is_Nothing -> elem -> case elem of - Nothing -> True - _ -> False - Not_Nothing -> elem -> case elem of - Nothing -> False - _ -> True - Is_True -> ==True - Is_False -> ==False + ## Converts a `Filter_Condition` condition into a predicate taking an + element and returning a value indicating whether the element should be + accepted by the filter. + to_predicate self = case self of + Less value -> <=value + Equal value -> ==value + Equal_Or_Greater value -> >=value + Greater value -> >value + Not_Equal value -> !=value + Between lower upper -> elem -> + (lower <= elem) && (elem <= upper) + Starts_With prefix -> _.starts_with prefix + Ends_With suffix -> _.ends_with suffix + Contains substring -> _.contains substring + Is_Nothing -> elem -> case elem of + Nothing -> True + _ -> False + Not_Nothing -> elem -> case elem of + Nothing -> False + _ -> True + Is_True -> ==True + Is_False -> ==False diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso index cdf1cefda2c3..6c59deefcffb 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso @@ -2,7 +2,6 @@ from Standard.Base.Data.Numbers import all from Standard.Base.Error.Common import Error from Standard.Base.Data.Boolean import True, False import Standard.Base.Data.Filter_Condition.Filter_Condition -import Standard.Base.Data.Filter_Condition as Filter_Condition_Module import Standard.Base.Function.Function import Standard.Base.Nothing import Standard.Base.Runtime.Unsafe @@ -183,7 +182,7 @@ type List example_filter = Examples.list.filter (Filter_Condition.Less than=3) filter : (Filter_Condition | (Any -> Boolean)) -> Vector Any filter self filter = case filter of - _ : Filter_Condition -> self.filter (Filter_Condition_Module.to_predicate filter) + _ : Filter_Condition -> self.filter filter.to_predicate predicate : Function -> go_filter list = case list of Cons h t -> diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso index 606e2205b483..2a752b5855a2 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Range.enso @@ -1,5 +1,4 @@ from Standard.Base import all -import Standard.Base.Data.Filter_Condition as Filter_Condition_Module # TODO Dubious constructor export from project.Data.Range.Range import all @@ -112,7 +111,7 @@ type Range (0.up_to 7).filter (Filter_Condition.Greater than=3) filter : (Filter_Condition | (Any -> Boolean)) -> Vector Any filter self filter = case filter of - _ : Filter_Condition -> self.filter (Filter_Condition_Module.to_predicate filter) + _ : Filter_Condition -> self.filter filter.to_predicate predicate : Function -> builder = self.fold Vector.new_builder builder-> elem-> if predicate elem then builder.append elem else builder diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 700728495b34..e59f1186e68f 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -1,7 +1,6 @@ from Standard.Base import all import Standard.Base.Data.Index_Sub_Range import Standard.Base.Random -import Standard.Base.Data.Filter_Condition as Filter_Condition_Module polyglot java import java.lang.IndexOutOfBoundsException polyglot java import org.enso.base.Array_Builder @@ -346,7 +345,7 @@ type Vector a [1, 2, 3, 4, 5].filter (Filter_Condition.Greater than=3) filter : (Filter_Condition | (Any -> Boolean)) -> Vector Any filter self filter = case filter of - _ : Filter_Condition -> self.filter (Filter_Condition_Module.to_predicate filter) + _ : Filter_Condition -> self.filter filter.to_predicate predicate : Function -> builder = self.fold new_builder builder-> elem-> if predicate elem then builder.append elem else builder