Skip to content

Commit 906dab4

Browse files
committed
Refactor tools
1 parent 2626424 commit 906dab4

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

tools/FunctionMap/FunctionMap.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling\FsToolkit.ErrorHandling.fsproj" />
1616
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling.TaskResult\FsToolkit.ErrorHandling.TaskResult.fsproj" />
1717
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
18+
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling.AsyncSeq\FsToolkit.ErrorHandling.AsyncSeq.fsproj" />
1819
</ItemGroup>
1920

2021
<Import Project="..\..\.paket\Paket.Restore.targets" />

tools/FunctionMap/Program.fs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,28 @@ open System
22
open System.Reflection
33

44
type Comparison =
5-
| Exact
6-
| Contains
5+
| Exact of string
6+
| Contains of string
77

88
let inline contains (value) (sequence : ^a) =
99
let bool = (^a : (member Contains : 'b -> bool) (sequence, value))
1010
bool
1111

12-
let inline comparison (value) (comparision, compareValue ) =
12+
let inline comparison (value) (comparision ) =
1313
match comparision with
14-
| Exact -> value = compareValue
15-
| Contains -> value |> contains compareValue
14+
| Exact compareValue -> value = compareValue
15+
| Contains compareValue -> value |> contains compareValue
1616

17-
let namesToFilter = [
18-
Exact, "GetType"
19-
Exact, "ToString"
20-
Exact, "Equals"
21-
Exact, "GetHashCode"
22-
Contains, "op_"
23-
]
2417

25-
let getMethodsByModuleName moduleName (types : Type seq) =
26-
types
27-
|> Seq.filter(fun t -> t.Name = moduleName)
28-
|> Seq.collect(fun t -> t.GetMethods())
29-
|> Seq.filter(fun m -> namesToFilter |> Seq.exists(comparison m.Name) |> not )
18+
let getMethodsByModuleName namesToFilter moduleName (types : Type seq) =
19+
let findWantedModules = Seq.filter(fun (t : Type) -> t.Name = moduleName)
20+
let getAllMethods = Seq.collect(fun (t : Type) -> t.GetMethods())
21+
let removeUnwantedMethods = Seq.filter(fun (m : MethodInfo) -> namesToFilter |> Seq.exists(comparison m.Name) |> not )
3022

23+
types
24+
|> findWantedModules
25+
|> getAllMethods
26+
|> removeUnwantedMethods
3127

3228
let report moduleName (methods : MethodInfo seq) =
3329
printfn "---%s---" moduleName
@@ -69,20 +65,19 @@ let allModules : list<Module>=
6965
Module.Create "JobResult" "JobResult"
7066
]
7167

72-
7368
let namespaceNormalizer = [
74-
Contains, "FSharp.Core", "FSharp.Core"
75-
Contains, "FsToolkit", "FsToolkit"
76-
Contains, "Hopac", "Hopac"
77-
Contains, "FSharpAsync", "FSharp.Core"
69+
Contains "FSharp.Core", "FSharp.Core"
70+
Contains"FsToolkit", "FsToolkit"
71+
Contains "Hopac", "Hopac"
72+
Contains "FSharpAsync", "FSharp.Core"
7873
]
7974

8075
let findInNamespaceNormalizer namespaceNormalizer item =
8176
namespaceNormalizer
82-
|> List.tryFind(fun (comparer, nameToCompare, _) ->
83-
comparison item (comparer, nameToCompare)
77+
|> List.tryFind(fun (comparer, _) ->
78+
comparison item (comparer)
8479
)
85-
|> Option.map(fun (_,_,normalizedName) -> normalizedName)
80+
|> Option.map(fun (_,normalizedName) -> normalizedName)
8681

8782
let createTableRow method modules =
8883
let outputModules = allModules |> List.map(fun m -> m.OutputName) |> List.distinct
@@ -110,6 +105,14 @@ let createMarkdownTable headers headersCount rows =
110105
for row in rows do
111106
printfn "%s" row
112107

108+
let namesToFilter = [
109+
Exact "GetType"
110+
Exact "ToString"
111+
Exact "Equals"
112+
Exact "GetHashCode"
113+
Contains "op_"
114+
]
115+
113116
[<EntryPoint>]
114117
let main argv =
115118
let types = [
@@ -118,8 +121,9 @@ let main argv =
118121
yield! Assembly.Load("FsToolkit.ErrorHandling.TaskResult").GetTypes()
119122
yield! Assembly.Load("Hopac").GetTypes()
120123
yield! Assembly.Load("FsToolkit.ErrorHandling.JobResult").GetTypes()
124+
yield! Assembly.Load("FsToolkit.ErrorHandling.AsyncSeq").GetTypes()
121125
]
122-
let getMethodsByModuleName name = getMethodsByModuleName name types
126+
let getMethodsByModuleName name = getMethodsByModuleName namesToFilter name types
123127
// types |> Seq.iter(fun f -> f.Name |> printfn "%s")
124128

125129
let headers, headersCount =
@@ -139,6 +143,5 @@ let main argv =
139143
createTableRow method (group)
140144
)
141145
|> createMarkdownTable headers headersCount
142-
143146

144147
0

0 commit comments

Comments
 (0)