Skip to content

Instantly share code, notes, and snippets.

@eelstork
Created August 1, 2020 20:23
Show Gist options
  • Save eelstork/2737f6ad4ed18820a9b7c6a6486aa215 to your computer and use it in GitHub Desktop.
Save eelstork/2737f6ad4ed18820a9b7c6a6486aa215 to your computer and use it in GitHub Desktop.
Time-sensitive cache; Howl code sample
// (╯°□°)╯ ⌢ C#
⊐ System; ⊐̥ UnityEngine.Time;
⊓ Active.Howl{
‒ ○ Cache<T> ¿ T: ⊟{
T? ω; ⒡<T> evaluator; ㅅ duration, end;
‒ Cache(⒡<T> φ, ㅅ expiry = 1f){
evaluator = φ; duration = expiry;
}
‒̥ ⁱ ⨕ T(Cache<T> x) → time > x.end ∨ x.ω ☰ ∅ ? +x : x.ω.Value;
‒̥ T ⨕ +(Cache<T> x){
x.end = time + x.duration;
⮐ (x.ω = x.evaluator()).Value;
}
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment