Skip to content

Commit 5f9b567

Browse files
committed
* added IndexList.partition (#90)
1 parent 19fc554 commit 5f9b567

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/FSharp.Data.Adaptive/Datastructures/IndexList.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,19 @@ type IndexList< [<EqualityConditionalOn>] 'T> internal(l : Index, h : Index, con
130130
if c.IsEmpty then IndexList.Empty
131131
else IndexList(MapExt.minKey c, MapExt.maxKey c, c)
132132

133+
/// Partitions the IndexList using the predicate.
134+
member x.Partition(predicate : Index -> 'T -> bool) =
135+
let a, b = MapExt.partition predicate content
133136

137+
let la =
138+
if MapExt.isEmpty a then IndexList.Empty
139+
else IndexList(MapExt.minKey a, MapExt.maxKey a, a)
140+
141+
let lb =
142+
if MapExt.isEmpty b then IndexList.Empty
143+
else IndexList(MapExt.minKey b, MapExt.maxKey b, b)
144+
145+
la, lb
134146

135147
/// Appends the given element to the list.
136148
member x.Add(element : 'T) =
@@ -885,6 +897,13 @@ module IndexList =
885897
| struct(ValueSome lmax, ValueSome rmin) ->
886898
IndexList<'T>(list.MinIndex, lmax, l), s, IndexList<'T>(rmin, list.MaxIndex, r)
887899

900+
/// partitions the list into two lists, the first containing all elements for which the predicate returns true,
901+
let partition (predicate : 'T -> bool) (list : IndexList<'T>) =
902+
list.Partition (fun _ v -> predicate v)
903+
904+
/// partitions the list into two lists, the first containing all elements for which the predicate returns true,
905+
let partitioni (predicate : Index -> 'T -> bool) (list : IndexList<'T>) =
906+
list.Partition predicate
888907

889908
/// updates or creates the element at the given index.
890909
/// note that out-of-bounds-indices will be ineffective.

0 commit comments

Comments
 (0)