読者です 読者をやめる 読者になる 読者になる

osiire’s blog

ふしぎなそふとやさん

自前のユーティリティ関数を晒してみる

let id x = x
let (@@) f x = f x
let ($) f g x = f (g x)
let (!$) = Lazy.force
let (+>) f g = g f

let curry f x y = f (x, y)
let uncurry f (x, y) = f x y
let flip f x y = f y x

let rec forever f x = 
  let v = f x in forever f v

let spawn_loop f x =
  ignore (Thread.create (forever f) x)

let maybe f x = try `Val (f x) with e -> `Err e
let tee f x = try ignore (f x); x with _ -> x

maybeとかteeとか普通に便利よー。