Add specs to hope_kv_list helpers.
[hope.git] / src / hope_kv_list.erl
index 12dbcd2..3ca9d07 100644 (file)
@@ -51,17 +51,17 @@ update(T, K, F) ->
     % TODO: Eliminate the 2nd lookup.
     set(T, K, V2).
 
-iter(T, Map1) ->
-    Map2 = lift_map_into_list(Map1),
-    lists:foreach(Map2, T).
+iter(T, F1) ->
+    F2 = lift_map(F1),
+    lists:foreach(F2, T).
 
-map(T, Map1) ->
-    Map2 = lift_map_into_list(Map1),
-    lists:map(Map2, T).
+map(T, F1) ->
+    F2 = fun ({K, _}=X) -> {K, apply_map(F1, X)} end,
+    lists:map(F2, T).
 
-filter(T, Map1) ->
-    Map2 = lift_map_into_list(Map1),
-    lists:filter(Map2, T).
+filter(T, F1) ->
+    F2 = lift_map(F1),
+    lists:filter(F2, T).
 
 fold(T, F1, Accumulator) ->
     F2 = fun ({K, V}, Acc) -> F1(K, V, Acc) end,
@@ -79,5 +79,15 @@ of_kv_list(List) ->
 %% Helpers
 %% ============================================================================
 
-lift_map_into_list(Map) ->
-    fun ({K, V}) -> {K, Map(K, V)} end.
+-spec lift_map(F) ->
+    G
+    when F :: fun(( K, V1 ) -> V2)
+       , G :: fun(({K, V1}) -> V2)
+       .
+lift_map(F) ->
+    fun (X) -> apply_map(F, X) end.
+
+-spec apply_map(fun((K, V1) -> V2), {K, V1}) ->
+    V2.
+apply_map(F, {K, V}) ->
+    F(K, V).
This page took 0.021943 seconds and 4 git commands to generate.