This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Laziness and optional memoization in pure Elm
version 1.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.0
Committed At 2017-07-01 19:48:33 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

Modules

README

elm-lazy

This library provides a way of putting of computations until they are needed, allowing for expensive calculations later.

lazySum : Lazy Int
lazySum =
    lazy (\() -> sum <| List.range 1 1000000)

It also gives you a way of storing a computed value so that you do not need to re-compute it.

lazySum : Int -> Lazy Int
lazySum n =
    lazy (\() -> sum <| List.range 0 n)


lazySums : List Int -> List (Lazy Int)
lazySums sums =
    List.map lazySum sums

-- evaluates the head, before putting it back on the list
evaluteCurrentSum : List (Lazy Int) -> List (Lazy Int)
evaluteCurrentSum xs =
   case xs of 
     head::rest -> Lazy.evaluate head :: rest
     _ -> []

Notes

This is a library based originally on the old Lazy implementation. However, it is written entirely in pure Elm. The main difference is explicit memoization, as we no longer use side-effects to achieve laziness.