Skip to content

Instantly share code, notes, and snippets.

@teoadal
Last active March 28, 2022 05:59
Show Gist options
  • Save teoadal/bfa0f260f865f5601617fcffa5d5252b to your computer and use it in GitHub Desktop.
Save teoadal/bfa0f260f865f5601617fcffa5d5252b to your computer and use it in GitHub Desktop.
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