Commit e06bc4c2 authored by POTTIER Francois's avatar POTTIER Francois

New function [Misc.once].

parent 0bf1f2b7
......@@ -363,3 +363,10 @@ let levels cmp xs =
| x1 :: xs ->
let ys1, yss = levels1 cmp x1 xs in
ys1 :: yss
let once x y =
let s = ref x in
fun () ->
let result = !s in
s := y;
result
......@@ -189,3 +189,8 @@ val best: ('a -> 'a -> bool) -> 'a list -> 'a option
run of adjacent equal elements. Every level is a nonempty list. *)
val levels: ('a -> 'a -> int) -> 'a list -> 'a list list
(* [once x y] produces a function [f] which produces [x] the first time it
is called and produces [y] forever thereafter. *)
val once: 'a -> 'a -> (unit -> 'a)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment