Created
August 1, 2020 20:23
-
-
Save eelstork/2737f6ad4ed18820a9b7c6a6486aa215 to your computer and use it in GitHub Desktop.
Time-sensitive cache; Howl code sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (╯°□°)╯ ⌢ 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