From b47be5d954a4bc60556d8a0b734ccc87c72159d2 Mon Sep 17 00:00:00 2001 From: nosami Date: Wed, 8 Nov 2023 21:08:20 +0000 Subject: [PATCH] Remove SeqUtil.filterToSome Slight refactoring. Seq.choose f is equivalent to Seq.map(f) |> SeqUtil.filterToSome --- Src/VimCore/CommandUtil.fs | 3 +-- Src/VimCore/FSharpUtil.fs | 9 --------- Src/VimCore/FoldManager.fs | 9 +++------ Src/VimCore/Interpreter_Interpreter.fs | 3 +-- Src/VimCore/KeyInput.fs | 6 ++---- Src/VimCore/MarkMap.fs | 3 +-- Src/VimCore/Register.fs | 6 ++---- Src/VimCore/SearchService.fs | 2 +- Src/VimCore/TaggerUtil.fs | 3 +-- Src/VimCore/VimSettings.fs | 4 +--- Src/VimCore/VimTextBuffer.fs | 3 +-- 11 files changed, 14 insertions(+), 37 deletions(-) diff --git a/Src/VimCore/CommandUtil.fs b/Src/VimCore/CommandUtil.fs index 50365bddf6..71524ab8ed 100644 --- a/Src/VimCore/CommandUtil.fs +++ b/Src/VimCore/CommandUtil.fs @@ -1451,8 +1451,7 @@ type internal CommandUtil } |> Seq.filter (fun (_, numberFormat) -> _localSettings.IsNumberFormatSupported numberFormat) - |> Seq.map (fun (func, _) -> func()) - |> SeqUtil.filterToSome + |> Seq.choose (fun (func, _) -> func()) |> Seq.sortByDescending (fun (_, span) -> span.Length) |> Seq.sortBy (fun (_, span) -> span.Start.Position) |> SeqUtil.tryHeadOnly diff --git a/Src/VimCore/FSharpUtil.fs b/Src/VimCore/FSharpUtil.fs index c93dcc92d3..644ef21cbd 100644 --- a/Src/VimCore/FSharpUtil.fs +++ b/Src/VimCore/FSharpUtil.fs @@ -296,15 +296,6 @@ module internal SeqUtil = index.Value <- index.Value + 1 } - /// Filter the list removing all None's - let filterToSome sequence = - seq { - for cur in sequence do - match cur with - | Some(value) -> yield value - | None -> () - } - /// Filters the list removing all of the first tuple arguments which are None let filterToSome2 (sequence: ('a option * 'b) seq) = seq { diff --git a/Src/VimCore/FoldManager.fs b/Src/VimCore/FoldManager.fs index 07c51b28ce..f158a21d3d 100644 --- a/Src/VimCore/FoldManager.fs +++ b/Src/VimCore/FoldManager.fs @@ -32,8 +32,7 @@ type internal FoldData member x.Folds = _folds |> Seq.ofList - |> Seq.map (TrackingSpanUtil.GetSpan _textBuffer.CurrentSnapshot) - |> SeqUtil.filterToSome + |> Seq.choose (TrackingSpanUtil.GetSpan _textBuffer.CurrentSnapshot) |> Seq.sortBy (fun span -> span.Start.Position) /// Create a fold over the given line range @@ -55,8 +54,7 @@ type internal FoldData let data = _folds |> Seq.map (fun span -> TrackingSpanUtil.GetSpan snapshot span,span) - |> Seq.map OptionUtil.combine2 - |> SeqUtil.filterToSome + |> Seq.choose OptionUtil.combine2 |> Seq.sortBy (fun (span,_) -> span.Start.Position) let ret = match data |> Seq.tryFind (fun (span,_) -> span.Contains(point)) with @@ -71,8 +69,7 @@ type internal FoldData member x.DeleteAllFolds (span: SnapshotSpan) = _folds <- _folds - |> Seq.map (TrackingSpanUtil.GetSpan _textBuffer.CurrentSnapshot) - |> SeqUtil.filterToSome + |> Seq.choose (TrackingSpanUtil.GetSpan _textBuffer.CurrentSnapshot) |> Seq.filter (fun s -> not (span.IntersectsWith(s))) |> Seq.map (fun span -> _textBuffer.CurrentSnapshot.CreateTrackingSpan(span.Span, SpanTrackingMode.EdgeInclusive)) |> List.ofSeq diff --git a/Src/VimCore/Interpreter_Interpreter.fs b/Src/VimCore/Interpreter_Interpreter.fs index de1315c6a4..f251049ad9 100644 --- a/Src/VimCore/Interpreter_Interpreter.fs +++ b/Src/VimCore/Interpreter_Interpreter.fs @@ -1074,13 +1074,12 @@ type VimInterpreter // Build up the status string messages let lines = displayNames - |> Seq.map (fun name -> + |> Seq.choose (fun name -> let register = _registerMap.GetRegister name match register.Name.Char, StringUtil.IsNullOrEmpty register.StringValue with | None, _ -> None | Some c, true -> None | Some c, false -> Some (c, normalizeDisplayString register.RegisterValue)) - |> SeqUtil.filterToSome |> Seq.map (fun (name, value) -> sprintf "\"%c %s" name value) let lines = Seq.append (Seq.singleton Resources.CommandMode_RegisterBanner) lines _statusUtil.OnStatusLong lines diff --git a/Src/VimCore/KeyInput.fs b/Src/VimCore/KeyInput.fs index beb579ebcc..8bc31d4c2b 100644 --- a/Src/VimCore/KeyInput.fs +++ b/Src/VimCore/KeyInput.fs @@ -249,8 +249,7 @@ module KeyInputUtil = let VimKeyCharSet = VimKeyInputList - |> Seq.map (fun ki -> ki.RawChar) - |> SeqUtil.filterToSome + |> Seq.choose (fun ki -> ki.RawChar) |> Set.ofSeq let VimKeyCharList = @@ -268,8 +267,7 @@ module KeyInputUtil = let CharToKeyInputMap = let inputs = VimKeyInputList - |> Seq.map (fun ki -> OptionUtil.combine ki.RawChar ki ) - |> SeqUtil.filterToSome + |> Seq.choose (fun ki -> OptionUtil.combine ki.RawChar ki ) |> Seq.filter (fun (_,ki) -> match ki.Key with | VimKey.Back -> false diff --git a/Src/VimCore/MarkMap.fs b/Src/VimCore/MarkMap.fs index 9c692aaa63..a11ab4920c 100644 --- a/Src/VimCore/MarkMap.fs +++ b/Src/VimCore/MarkMap.fs @@ -67,14 +67,13 @@ type MarkMap(_bufferTrackingService: IBufferTrackingService) = member x.GlobalMarks = _globalMarkMap |> Seq.map (fun keyValuePair -> keyValuePair.Key) - |> Seq.map (fun letter -> + |> Seq.choose (fun letter -> match x.GetGlobalMarkData letter with | None -> None | Some (_, trackingLineColumn, _) -> match trackingLineColumn.VirtualPoint with | None -> None | Some virtualPoint -> Some (letter, virtualPoint)) - |> SeqUtil.filterToSome /// Get the global mark location member x.GetGlobalMark letter = diff --git a/Src/VimCore/Register.fs b/Src/VimCore/Register.fs index c55a2e5ab2..3595f6f4f6 100644 --- a/Src/VimCore/Register.fs +++ b/Src/VimCore/Register.fs @@ -433,16 +433,14 @@ module RegisterNameUtil = /// All of the char values which represent register names let RegisterNameChars = RegisterName.All - |> Seq.map (fun n -> n.Char) - |> SeqUtil.filterToSome + |> Seq.choose (fun n -> n.Char) |> List.ofSeq /// Mapping of the available char's to the appropriate RegisterName let RegisterMap = RegisterName.All |> Seq.map (fun r -> (r.Char),r) - |> Seq.map OptionUtil.combine2 - |> SeqUtil.filterToSome + |> Seq.choose OptionUtil.combine2 |> Map.ofSeq let CharToRegister c = Map.tryFind c RegisterMap diff --git a/Src/VimCore/SearchService.fs b/Src/VimCore/SearchService.fs index 37d719fe08..2603642852 100644 --- a/Src/VimCore/SearchService.fs +++ b/Src/VimCore/SearchService.fs @@ -81,7 +81,7 @@ type internal EditorSearchService member private x.FindNextInCache (findData: FindData) (position: int) = lock (_cacheArray) (fun () -> _cacheArray - |> SeqUtil.filterToSome + |> Seq.choose id |> Seq.tryFind (fun cacheEntry -> cacheEntry.Matches findData position) |> Option.map (fun cacheEntry -> SnapshotSpan(findData.TextSnapshotToSearch, cacheEntry.FoundSpan))) diff --git a/Src/VimCore/TaggerUtil.fs b/Src/VimCore/TaggerUtil.fs index 69b0289b7b..697a2c7d5b 100644 --- a/Src/VimCore/TaggerUtil.fs +++ b/Src/VimCore/TaggerUtil.fs @@ -578,11 +578,10 @@ type internal TrackingCacheData<'TTag when 'TTag :> ITag> // Mapping gave us at least partial information. Will work for the transition // period x.TrackingList - |> Seq.map (fun (span, tag) -> + |> Seq.choose (fun (span, tag) -> match TrackingSpanUtil.GetSpan snapshot span with | None -> None | Some span -> TagSpan<'TTag>(span, tag) :> ITagSpan<'TTag> |> Some) - |> SeqUtil.filterToSome |> ReadOnlyCollectionUtil.OfSeq /// This holds the set of data which is currently known from the background thread. Data in diff --git a/Src/VimCore/VimSettings.fs b/Src/VimCore/VimSettings.fs index 6b6e78c1f3..d752e5c25b 100644 --- a/Src/VimCore/VimSettings.fs +++ b/Src/VimCore/VimSettings.fs @@ -267,13 +267,11 @@ type internal GlobalSettings() = member x.SetCommaOptions name mappingList options testFunc = let settingValue = mappingList - |> Seq.ofList - |> Seq.map (fun (name, value) -> + |> List.choose (fun (name, value) -> if testFunc options value then Some name else None) - |> SeqUtil.filterToSome |> String.concat "," _map.TrySetValue name (SettingValue.String settingValue) |> ignore diff --git a/Src/VimCore/VimTextBuffer.fs b/Src/VimCore/VimTextBuffer.fs index 7745a5ce63..ec57c70966 100644 --- a/Src/VimCore/VimTextBuffer.fs +++ b/Src/VimCore/VimTextBuffer.fs @@ -194,11 +194,10 @@ type internal VimTextBuffer /// Get all of the local marks in the IVimTextBuffer. member x.LocalMarks = LocalMark.All - |> Seq.map (fun localMark -> + |> Seq.choose (fun localMark -> match x.GetLocalMark localMark with | None -> None | Some point -> Some (localMark, point)) - |> SeqUtil.filterToSome /// Whether to use virtual space member x.UseVirtualSpace =