Skip to content

Commit 7e74c84

Browse files
committed
Update Seq.filter + maps into Seq.choose
1 parent 4140311 commit 7e74c84

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/Common/StringParsing.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ module String =
108108
let removeSpaces (lines: string list) =
109109
let spaces =
110110
lines
111-
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
112-
|> Seq.map (fun line -> line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length)
111+
|> Seq.choose (fun line ->
112+
if not <| String.IsNullOrWhiteSpace line then
113+
line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length |> Some
114+
else
115+
None)
113116
|> fun xs -> if Seq.isEmpty xs then 0 else Seq.min xs
114117

115118
lines

src/FSharp.Formatting.ApiDocs/GenerateModel.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,8 +2264,11 @@ module internal SymbolReader =
22642264
do
22652265
replacedParagraphs
22662266
|> Seq.collect collectParagraphIndirectLinks
2267-
|> Seq.filter (linkNotDefined doc)
2268-
|> Seq.map (getTypeLink ctx)
2267+
|> Seq.choose (fun line ->
2268+
if linkNotDefined doc line then
2269+
getTypeLink ctx line |> Some
2270+
else
2271+
None)
22692272
|> Seq.iter (addLinkToType doc)
22702273

22712274
doc.With(paragraphs = replacedParagraphs)

src/FSharp.Formatting.Common/Templating.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ type FrontMatterFile =
4848
// Allow empty lines in frontmatter
4949
let isBlankLine = String.IsNullOrWhiteSpace line
5050
isBlankLine || line.Contains(":"))
51-
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
52-
|> Seq.map (fun line ->
53-
let parts = line.Split(":")
54-
parts.[0].ToLowerInvariant(), parts.[1])
51+
|> Seq.choose (fun line ->
52+
let parts = line.Split(":") |> Array.toList
53+
54+
if not <| String.IsNullOrWhiteSpace line then
55+
match parts with
56+
| first :: second :: _ -> Some(first.ToLowerInvariant(), second)
57+
| _ -> None
58+
else
59+
None)
5560
|> Map.ofSeq
5661

5762
match

0 commit comments

Comments
 (0)