once: memoization for IO actions and functions

[ data, gpl, library ] [ Propose Tags ]

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
Versions 0.1.0.0, 0.2, 0.3
Dependencies base (>=4.7 && <5), containers (>=0.5), hashable (>=1.2), template-haskell (>=2.10), unordered-containers (>=0.2) [details]
License GPL-3.0-only
Copyright 2015-2018 Dmitry Bogatov
Author Dmitry Bogatov
Maintainer KAction@debian.org
Category Data
Home page https://gitlab.com/kaction/haskell-once
Source repo head: git clone https://gitlab.com/kaction/haskell-once
Uploaded by DmitryBogatov at Fri Nov 9 04:44:01 UTC 2018
Distributions LTSHaskell:0.2, NixOS:0.3, Stackage:0.3
Downloads 671 total (40 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-11-09 [all 1 reports]
Hackage Matrix CI

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees