Source

OCamlRuby / util.ml

Full commit
let (@@) f x = f x
let ($) g f = fun x -> g (f x)
let id x = x
let p = Printf.printf
let pr = print_endline

let slist delim show l =
  String.concat delim @@ List.map show l

let const c = fun _ -> c

let mapi f l =
  List.fold_left (fun (i,store) b -> (i+1,f i b::store)) (0,[]) l

type ('l, 'r) either = Inl of 'l | Inr of 'r

let list_of_hash t = Hashtbl.fold (fun k v store -> (k,v) :: store) t []

(* じじぃの日記、ツッコミ可より http://jijixi.azito.com/cgi-bin/diary/index.rb?date=20060617#p08 *)
let stream_map f stream =                                                    
    Stream.from (fun i ->
      try Some (f (Stream.next stream))
      with Stream.Failure -> None);;