Last active
March 28, 2022 05:59
-
-
Save teoadal/bfa0f260f865f5601617fcffa5d5252b to your computer and use it in GitHub Desktop.
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
private sealed class Closure<T> { | |
private readonly Action<T> _action; | |
private readonly Action _closure; | |
private T _value; | |
public Closure(Action<T> action) { | |
_action = action; | |
_closure = Execute; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public void Clear() => _value = default; | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public Action Prepare(T value) { | |
_value = value; | |
return _closure; | |
} | |
private void Execute() => _action(_value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment