Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [<ImmutableObject true>]
- type Status(value : bool) =
- let Value = value
- member this.Positive
- with get() = if value then true else false
- member this.Negative
- with get() = if value then false else true
- [<ImmutableObject true>]
- type WhenResult<'TIn>(value: 'TIn, status: bool) =
- member this.Status : Status = new Status(status)
- member this.Value = value
- [<Extension>]
- type SelectivelyExecuteExtension =
- [<Extension>]
- static member inline When<'TIn>(self: 'TIn, action: Func<'TIn,bool>) =
- new WhenResult<'TIn>(self, action.Invoke self)
- [<Extension>]
- static member inline Do<'TIn>(result: WhenResult<'TIn>, action: Action<'TIn>) =
- if result.Status.Positive
- then action.Invoke(result.Value)
- result
- [<Extension>]
- static member inline Else<'TIn>(result: WhenResult<'TIn>, action: Func<'TIn,'TIn>) =
- if result.Status.Negative
- then action.Invoke(result.Value)
- else result.Value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement