diff --git a/docsrc/content/extensions.fsx b/docsrc/content/extensions.fsx index bb38da66a..6ed266d50 100644 --- a/docsrc/content/extensions.fsx +++ b/docsrc/content/extensions.fsx @@ -186,6 +186,7 @@ The String type: * truncate, drop * findIndex, tryFindIndex * findSliceIndex, tryFindSliceIndex + * findLastSliceIndex, tryFindLastSliceIndex * toArray, ofArray, toList, ofList, toSeq, ofSeq, toCodePoints, ofCodePoints * getBytes @@ -195,6 +196,7 @@ Collections / Traversable types: * intercalate, intersperse, * split, replace, * findSliceIndex, trySliceIndex, + * findLastSliceIndex, tryLastSliceIndex, * partitionMap * [IList](reference/fsharpplus-ilist.html) * toIReadOnlyList @@ -207,6 +209,7 @@ Collections / Traversable types: * split, replace, * toIReadOnlyList, * findSliceIndex, tryFindSliceIndex, + * findLastSliceIndex, tryLastSliceIndex, * partitionMap * setAt, removeAt * [Enumerator](reference/fsharpplus-enumerator.html) @@ -232,6 +235,7 @@ Collections / Traversable types: * replicate * toIReadOnlyList * findSliceIndex, tryFindSliceIndex + * findLastSliceIndex, tryLastSliceIndex, * [ IReadOnlyCollection ](reference/fsharpplus-ireadonlycollection.html) * ofArray, ofList, ofSeq * map diff --git a/src/FSharpPlus/Internals.fs b/src/FSharpPlus/Internals.fs index ec38039d4..deb064df8 100644 --- a/src/FSharpPlus/Internals.fs +++ b/src/FSharpPlus/Internals.fs @@ -429,7 +429,7 @@ module FindLastSliceIndex = // we assume the slice is finite (otherwise it cannot be searched) let slice = slice |> Seq.toArray use sourceEnumerator = source.GetEnumerator() - // we also assume either the source is finite + // we also assume the source is finite let rec go last index = if sourceEnumerator.MoveNext() then cache.Enqueue sourceEnumerator.Current @@ -503,7 +503,7 @@ module FindLastSliceIndex = let h = source.[index] cache.Enqueue h if cache.Count = slice.Length then - if sequenceEqual cache revSlice then index - slice.Length + 1 + if sequenceEqual cache revSlice then index else cache.Dequeue() |> ignore go (index - 1) diff --git a/tests/FSharpPlus.Tests/General.fs b/tests/FSharpPlus.Tests/General.fs index 4b9b2f7a3..ef124e1b5 100644 --- a/tests/FSharpPlus.Tests/General.fs +++ b/tests/FSharpPlus.Tests/General.fs @@ -112,15 +112,12 @@ type WrappedListD<'s> = WrappedListD of 's list with WrappedListD (traversei f x : ^r) static member FindIndex (WrappedListD x, y) = SideEffects.add "Using WrappedListD's FindIndex" - printfn "WrappedListD.FindIndex" findIndex y x static member FindSliceIndex (WrappedListD x, WrappedListD y) = SideEffects.add "Using WrappedListD's FindSliceIndex" - printfn "WrappedListD.FindSliceIndex" findSliceIndex y x static member FindLastSliceIndex (WrappedListD x, WrappedListD y) = SideEffects.add "Using WrappedListD's FindLastSliceIndex" - printfn "WrappedListD.FindLastSliceIndex" findLastSliceIndex y x member this.Length = SideEffects.add "Using WrappedListD's Length" diff --git a/tests/FSharpPlusFable.Tests/FSharpTests/General/Util.fs b/tests/FSharpPlusFable.Tests/FSharpTests/General/Util.fs index a12f4f4ea..711a12071 100644 --- a/tests/FSharpPlusFable.Tests/FSharpTests/General/Util.fs +++ b/tests/FSharpPlusFable.Tests/FSharpTests/General/Util.fs @@ -103,12 +103,13 @@ type WrappedListD<'s> = WrappedListD of 's list with WrappedListD (traversei f x : ^r) static member FindIndex (WrappedListD x, y) = SideEffects.add "Using WrappedListD's FindIndex" - printfn "WrappedListD.FindIndex" findIndex y x static member FindSliceIndex (WrappedListD x, WrappedListD y) = SideEffects.add "Using WrappedListD's FindSliceIndex" - printfn "WrappedListD.FindSliceIndex" findSliceIndex y x + static member FindLastSliceIndex (WrappedListD x, WrappedListD y) = + SideEffects.add "Using WrappedListD's FindLastSliceIndex" + findLastSliceIndex y x member this.Length = SideEffects.add "Using WrappedListD's Length" let (WrappedListD lst) = this