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 2274, Tue Jan 30 15:00:09 2007 UTC revision 3759, Sun Sep 23 13:07:11 2012 UTC
# Line 1  Line 1
1  (* list-map-fn.sml  (* list-map-fn.sml
2   *   *
3     * COPYRIGHT (c) 2012 The Fellowship of SML/NJ (http://www.smlnj.org)
5     *
6   * COPYRIGHT (c) 1996 by AT&T Research.  See COPYRIGHT file for details.   * COPYRIGHT (c) 1996 by AT&T Research.  See COPYRIGHT file for details.
7   *   *
8   * An implementation of finite maps on ordered keys, which uses a sorted list   * An implementation of finite maps on ordered keys, which uses a sorted list
# Line 243  Line 246
246            end            end
247      fun mapPartial f l = mapPartiali (fn (_, item) => f item) l      fun mapPartial f l = mapPartiali (fn (_, item) => f item) l
248
249      (* check the elements of a map with a predicate and return true if
250       * any element satisfies the predicate. Return false otherwise.
251       * Elements are checked in key order.
252       *)
253        fun exists pred = let
254              fun exists' [] = false
255                | exists' ((_, x)::r) = pred x orelse exists' r
256              in
257                exists'
258              end
259        fun existsi pred = let
260              fun exists' [] = false
261                | exists' (arg::r) = pred arg orelse exists' r
262              in
263                exists'
264              end
265
266      (* check the elements of a map with a predicate and return true if
267       * they all satisfy the predicate. Return false otherwise.  Elements
268       * are checked in key order.
269       *)
270        fun all pred = let
271              fun all' [] = false
272                | all' ((_, x)::r) = pred x andalso all' r
273              in
274                all'
275              end
276        fun alli pred = let
277              fun all' [] = false
278                | all' (arg::r) = pred arg andalso all' r
279              in
280                all'
281              end
282
283    end (* functor ListMapFn *)    end (* functor ListMapFn *)
284

Legend:
 Removed from v.2274 changed lines Added in v.3759