Skip to content

Commit

Permalink
Update Seq.filter + maps into Seq.choose
Browse files Browse the repository at this point in the history
  • Loading branch information
1eyewonder committed Jun 13, 2024
1 parent 4140311 commit 7e74c84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/Common/StringParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ module String =
let removeSpaces (lines: string list) =
let spaces =
lines
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
|> Seq.map (fun line -> line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length)
|> Seq.choose (fun line ->
if not <| String.IsNullOrWhiteSpace line then
line |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length |> Some
else
None)
|> fun xs -> if Seq.isEmpty xs then 0 else Seq.min xs

lines
Expand Down
7 changes: 5 additions & 2 deletions src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,8 +2264,11 @@ module internal SymbolReader =
do
replacedParagraphs
|> Seq.collect collectParagraphIndirectLinks
|> Seq.filter (linkNotDefined doc)
|> Seq.map (getTypeLink ctx)
|> Seq.choose (fun line ->
if linkNotDefined doc line then
getTypeLink ctx line |> Some
else
None)
|> Seq.iter (addLinkToType doc)

doc.With(paragraphs = replacedParagraphs)
Expand Down
13 changes: 9 additions & 4 deletions src/FSharp.Formatting.Common/Templating.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ type FrontMatterFile =
// Allow empty lines in frontmatter
let isBlankLine = String.IsNullOrWhiteSpace line
isBlankLine || line.Contains(":"))
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
|> Seq.map (fun line ->
let parts = line.Split(":")
parts.[0].ToLowerInvariant(), parts.[1])
|> Seq.choose (fun line ->
let parts = line.Split(":") |> Array.toList

if not <| String.IsNullOrWhiteSpace line then
match parts with
| first :: second :: _ -> Some(first.ToLowerInvariant(), second)
| _ -> None
else
None)
|> Map.ofSeq

match
Expand Down

0 comments on commit 7e74c84

Please sign in to comment.