<commit_before>module Memo (memo) where

{-| Most basic memoization functionality.

@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 =
  apply << Dict.fromList << List.map (\arg -> ( arg, Lazy.lazy (\() -> fun arg) ))<commit_msg>small refactoring<commit_after>module Memo (memo) where

{-| Most basic memoization functionality.

@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))
{'fraction_non_alphanumeric': 0.1487985212569316, 'fraction_numerical': 0.0, 'mean_word_length': 3.2470588235294118, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5059435', 'n_tokens_mistral': 370, 'n_tokens_neox': 357, 'n_words': 123}