GPL-3.0-only licensed by Dmitry Bogatov
Maintained by KAction@debian.org

Module documentation for 0.4

This version can be pinned in stack with:once-0.4@sha256:ce30b72cd90f6eb729f3ad77ac3daf8117d60b6be961b511b46ae1ce4872519c,2463

Package provides single polymorphic function once, that allows you to memoize IO actions and functions, evaluating them at most once.

let mkStamp = (putStrLn "stamping" >> writeFile "/tmp/stamp" "") :: IO ()
-- onceStamp :: IO ()
onceStamp <- once mkStamp
-- onceStamp actually evaluates mkStamp it wraps first time.
onceStamp
stamping
-- but second time result `()' is memoized, no action is performed.
onceStamp
-- we can memoize functions too
foo <- once $ \x -> print "foo" >> print (x :: Int)
-- action will be performed once for every distinct argument
foo 10
foo
10
foo 10
10
foo 4
foo
4
comments powered byDisqus