-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from linksplatform/feature/add_handler_state_s…
…truct Add `(Write|Read)HandlerState` struct
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using Platform.Delegates; | ||
|
||
namespace Platform.Data | ||
{ | ||
public struct ReadHandlerState<TLink> | ||
{ | ||
private readonly EqualityComparer<TLink> _equalityComparer; | ||
public TLink Result; | ||
public ReadHandler<TLink> Handler; | ||
public TLink Continue; | ||
public TLink Break; | ||
|
||
public ReadHandlerState(TLink @continue, TLink @break, ReadHandler<TLink> handler) | ||
{ | ||
_equalityComparer = EqualityComparer<TLink>.Default; | ||
Continue = @continue; | ||
Break = @break; | ||
Result = @continue; | ||
Handler = handler; | ||
} | ||
|
||
public void Apply(TLink result) | ||
{ | ||
if (_equalityComparer.Equals(Break, Result)) | ||
{ | ||
return; | ||
} | ||
if (!_equalityComparer.Equals(Break, result)) | ||
{ | ||
return; | ||
} | ||
Handler = null; | ||
Result = Break; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using Platform.Delegates; | ||
|
||
namespace Platform.Data | ||
{ | ||
public struct WriteHandlerState<TLink> | ||
{ | ||
private readonly EqualityComparer<TLink> _equalityComparer; | ||
public TLink Result; | ||
public WriteHandler<TLink> Handler; | ||
public TLink Continue; | ||
public TLink Break; | ||
|
||
public WriteHandlerState(TLink @continue, TLink @break, WriteHandler<TLink> handler) | ||
{ | ||
_equalityComparer = EqualityComparer<TLink>.Default; | ||
Continue = @continue; | ||
Break = @break; | ||
Result = @continue; | ||
Handler = handler; | ||
} | ||
|
||
public void Apply(TLink result) | ||
{ | ||
if (_equalityComparer.Equals(Break, Result)) | ||
{ | ||
return; | ||
} | ||
if (!_equalityComparer.Equals(Break, result)) | ||
{ | ||
return; | ||
} | ||
Handler = null; | ||
Result = Break; | ||
} | ||
} | ||
} | ||
|
||
|