Permalink
Browse files

[enhance] map: added rev_foldi

  • Loading branch information...
1 parent 5a313b3 commit 53d39d7beb556032f6755346cdeb6a3a02bc2b35 @Aqua-Ye Aqua-Ye committed Apr 11, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 stdlib/core/map/map.opa
View
@@ -177,6 +177,7 @@ type Map('key,'order) =
fold : ('key,'val,'acc -> 'acc), ordered_map('key,'val,'order), 'acc -> 'acc
rev_fold: ('key,'val,'acc -> 'acc), ordered_map('key,'val,'order), 'acc -> 'acc
foldi : (int,'key,'val,'acc -> 'acc), ordered_map('key,'val,'order), 'acc -> 'acc
+ rev_foldi : (int,'key,'val,'acc -> 'acc), ordered_map('key,'val,'order), 'acc -> 'acc
filter_map : (('value -> option('new_value)), ordered_map('key, 'value, 'order) -> ordered_map('key, 'new_value, 'order))
@@ -511,6 +512,15 @@ Map_private =
aux(right, f(cpt+1, key, value, acc), cpt+1)
aux(m, acc, 0).f1
+ rev_foldi((f:(int, 'key, 'val, 'acc -> 'acc)), m:Map_private.map('key, 'val), acc:'acc) : 'acc =
+ rec aux(m, acc, cpt) =
+ match m
+ | { empty } -> (acc:'acc, cpt)
+ | ~{ left key:'key value:'val right height=_ } ->
+ (acc, cpt) = aux(right, acc, cpt)
+ aux(left, f(cpt+1, key, value, acc), cpt+1)
+ aux(m, acc, 0).f1
+
filter_map(order:order('key,_), f:('a -> option('b)), m:Map_private.map('key, 'a)) : Map_private.map('key,'b) =
fold(
@@ -752,6 +762,10 @@ Map_make(order: order('key,'order) ) : Map =
'acc, m : ordered_map('key, 'val, 'order), acc : 'acc) =
Map_private.foldi(f, m, acc) : 'acc
+ rev_foldi(f : int, 'key, 'val, 'acc ->
+ 'acc, m : ordered_map('key, 'val, 'order), acc : 'acc) =
+ Map_private.rev_foldi(f, m, acc) : 'acc
+
map(f : ('val -> 'new_val), m : ordered_map('key, 'val, 'order)) :
ordered_map('key, 'new_val, 'order) =
Map_private.map(f,m)

0 comments on commit 53d39d7

Please sign in to comment.