Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /smlnj-lib/trunk/Util/list-map-fn.sml
 [smlnj] / smlnj-lib / trunk / Util / list-map-fn.sml

# Diff of /smlnj-lib/trunk/Util/list-map-fn.sml

revision 1192, Wed May 15 14:02:06 2002 UTC revision 1193, Thu May 16 18:44:04 2002 UTC
# Line 159  Line 159
159              merge (m1, m2, [])              merge (m1, m2, [])
160            end            end
161
162        fun mergeWith f (m1 : 'a map, m2 : 'b map) = let
163              fun merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), l) = (
164                    case Key.compare (k1, k2)
165                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, l)
166                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, l)
167                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, l)
168                    (* end case *))
169                | merge ([], [], l) = List.rev l
170                | merge ((k1, x1)::r1, [], l) = mergef (k1, SOME x1, NONE, r1, [], l)
171                | merge ([], (k2, x2)::r2, l) = mergef (k2, NONE, SOME x2, [], r2, l)
172              and mergef (k, x1, x2, r1, r2, l) = (case f (x1, x2)
173                     of NONE => merge (r1, r2, l)
174                      | SOME y => merge (r1, r2, (k, y)::l)
175                    (* end case *))
176              in
177                merge (m1, m2, [])
178              end
179        fun mergeWithi f (m1 : 'a map, m2 : 'b map) = let
180              fun merge (m1 as ((k1, x1)::r1), m2 as ((k2, x2)::r2), l) = (
181                    case Key.compare (k1, k2)
182                     of LESS => mergef (k1, SOME x1, NONE, r1, m2, l)
183                      | EQUAL => mergef (k1, SOME x1, SOME x2, r1, r2, l)
184                      | GREATER => mergef (k2, NONE, SOME x2, m1, r2, l)
185                    (* end case *))
186                | merge ([], [], l) = List.rev l
187                | merge ((k1, x1)::r1, [], l) = mergef (k1, SOME x1, NONE, r1, [], l)
188                | merge ([], (k2, x2)::r2, l) = mergef (k2, NONE, SOME x2, [], r2, l)
189              and mergef (k, x1, x2, r1, r2, l) = (case f (k, x1, x2)
190                     of NONE => merge (r1, r2, l)
191                      | SOME y => merge (r1, r2, (k, y)::l)
192                    (* end case *))
193              in
194                merge (m1, m2, [])
195              end
196
197    (* Apply a function to the entries of the map in map order. *)    (* Apply a function to the entries of the map in map order. *)
198      val appi = List.app      val appi = List.app
199      fun app f l = appi (fn (_, item) => f item) l      fun app f l = appi (fn (_, item) => f item) l

Legend:
 Removed from v.1192 changed lines Added in v.1193