Skip to content

Commit

Permalink
Merge pull request #3077 from nosami/dev/nosami/remove-filterToSome
Browse files Browse the repository at this point in the history
Remove SeqUtil.filterToSome
  • Loading branch information
nosami committed Nov 16, 2023
2 parents d4afbd9 + b47be5d commit 3bc7ce5
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Src/VimCore/CommandUtil.fs
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions Src/VimCore/FSharpUtil.fs
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions Src/VimCore/FoldManager.fs
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Src/VimCore/Interpreter_Interpreter.fs
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions Src/VimCore/KeyInput.fs
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Src/VimCore/MarkMap.fs
Expand Up @@ -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 =
Expand Down
6 changes: 2 additions & 4 deletions Src/VimCore/Register.fs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Src/VimCore/SearchService.fs
Expand Up @@ -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)))

Expand Down
3 changes: 1 addition & 2 deletions Src/VimCore/TaggerUtil.fs
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Src/VimCore/VimSettings.fs
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions Src/VimCore/VimTextBuffer.fs
Expand Up @@ -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 =
Expand Down

0 comments on commit 3bc7ce5

Please sign in to comment.