This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
README

Memo

Most basic memoization functionality.

For documentation, see the README.

memo : (comparable -> b) -> List comparable -> comparable -> Maybe b
module Memo exposing (memo)

{-| Most basic memoization functionality.

For documentation, see the [README](.).

@docs memo
-}

import Dict exposing (Dict)
import Lazy exposing (Lazy)


{-|
-}
type alias Function comparable b =
    Dict comparable (Lazy b)


{-|
-}
apply : Function comparable b -> comparable -> Maybe b
apply dict =
    \arg -> Maybe.map Lazy.force (Dict.get arg dict)


{-|
-}
memo : (comparable -> b) -> List comparable -> comparable -> Maybe b
memo fun args =
    apply (Dict.fromList (List.map (\arg -> ( arg, Lazy.lazy (\() -> fun arg) )) args))