11spec_to_ast = fn a , b -> Kernel.Typespec . spec_to_ast ( a , b ) end
22
33y = fn f ->
4- fn x ->
4+ fun = fn x ->
55 f . ( fn y -> ( x . ( x ) ) . ( y ) end )
6- end . ( fn x ->
7- f . ( fn y -> ( x . ( x ) ) . ( y ) end )
8- end )
6+ end
7+ fun . ( fun )
8+ end
9+
10+ y2 = fn f ->
11+ fun = fn x ->
12+ f . ( fn y , z -> ( x . ( x ) ) . ( y , z ) end )
13+ end
14+ fun . ( fun )
915end
1016
1117
12- replaceTypeGen = fn replaceType ->
18+ replaceTypes = fn replaceType ->
1319 fn
14- [ { spec } | specs ] , types ->
15- [ ]
20+ [ { type , line , name , args } | types ] , typesMap ->
21+ IO . puts "replacing"
22+ case typesMap [ name ] do
23+ nil -> [ { type , line , name , replaceType . ( args , typesMap ) } | replaceType . ( types , typesMap ) ]
24+ type -> [ type | replaceType . ( types , typesMap ) ]
25+ end
26+ #[{type, line, name, replaceType.(args, typesMap)} | replaceType.(types, typesMap)]
27+ [ type | types ] , typesMap -> [ type | replaceType . ( types , typesMap ) ]
28+ [ ] , _ -> [ ]
1629 end
1730end
31+ replaceTypes = y2 . ( replaceTypes )
32+
33+
1834
1935zipFunSpec = fn
2036 ( a , nil ) -> a
@@ -25,20 +41,26 @@ zipFunSpec = fn
2541 IO . inspect a
2642 a <> "@" <> first
2743end
44+ mapper = fn { { name , arity } , types } , typesMap ->
45+
46+ spec = types
47+ |> replaceTypes . ( typesMap )
48+ |> Enum . map ( & spec_to_ast . ( name , & 1 ) )
49+ |> Enum . map ( & Macro . to_string / 1 )
2850
51+ { Atom . to_string ( name ) , spec }
52+ end
53+ reducer = fn { k , v } , acc ->
54+ Dict . put ( acc , k , v )
55+ end
2956getSpec = fn module ->
30- mapper = fn { { name , arity } , types } ->
31- specs = types
32- |> Enum . map ( & ( spec_to_ast . ( name , & 1 ) ) )
33- |> Enum . map ( & Macro . to_string / 1 )
34- { Atom . to_string ( name ) , specs }
35- end
36- reducer = fn { k , v } , acc ->
37- Dict . put ( acc , k , v )
57+ type_aliases = ( Kernel.Typespec . beam_types ( module ) || [ ] )
58+ |> Enum . reduce % { } , fn
59+ ( { :type , { name , type , arg } } , b ) -> Map . put ( b , name , type )
3860 end
3961
40- Kernel.Typespec . beam_specs ( module )
41- |> Enum . map ( mapper )
62+ ( Kernel.Typespec . beam_specs ( module ) || [ ] )
63+ |> Enum . map ( & mapper . ( & 1 , type_aliases ) )
4264 |> Enum . reduce ( % { } , reducer )
4365end
4466
@@ -51,7 +73,7 @@ pairWithSpec = fn input, fns ->
5173 re = ~r/ \/ \d +\s *$/
5274 Enum . map ( fns , fn a ->
5375 b = Dict . get ( specMap , Regex . replace ( re , List . to_string ( a ) , "" ) )
54- # IO.inspect specMap
76+ IO . inspect specMap
5577 #IO.inspect b
5678 zipFunSpec . ( List . to_string ( a ) , b )
5779 end )
0 commit comments