Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[enhance] set: added a utility function to filter a set

  • Loading branch information...
commit 2f923b139337bd58a3387d05e305be7297af88d7 1 parent 2c64387
@Aqua-Ye Aqua-Ye authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 stdlib/core/set/set.opa
View
9 stdlib/core/set/set.opa
@@ -110,6 +110,11 @@ type Set('elem,'order) =
find : ('elem -> bool), ordered_set('elem,'order) -> option('elem)
/**
+ * Filter a set of elements
+ */
+ filter : ('elem -> bool), ordered_set('elem,'order) -> ordered_set('elem,'order)
+
+ /**
* Loop through a set, collecting data from the set.
*
* This function guarantees that all elements of the set will be visited.
@@ -321,6 +326,10 @@ Set_make( order : order('elem,'order) ) =
{none} -> none
{some={~key val=_}} -> some(key) : option('elem)
+ filter( f : 'elem -> bool, set : ordered_set('elem, 'order)) =
+ MapSet.fold((k,_v,a -> if f(k) then MapSet.add(k,void,a) else a), set, MapSet.empty)
+ : ordered_set('elem, 'order)
+
fold(fun: ('elem, 'acc -> 'acc), set: ordered_set('elem,'order), acc : 'acc) =
MapSet.fold((k,_v,a -> fun(k,a)), set, acc)
: 'acc
Please sign in to comment.
Something went wrong with that request. Please try again.