Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.03 KB | None | 0 0
  1. [<ImmutableObject true>]
  2. type Status(value : bool) =
  3.     let Value = value
  4.  
  5.     member this.Positive
  6.         with get() = if value then true else false
  7.    
  8.     member this.Negative
  9.         with get() = if value then false else true
  10.  
  11. [<ImmutableObject true>]
  12. type WhenResult<'TIn>(value: 'TIn, status: bool)  =
  13.     member this.Status : Status = new Status(status)
  14.     member this.Value = value
  15.  
  16.  
  17.  
  18. [<Extension>]
  19. type SelectivelyExecuteExtension =
  20.    
  21.     [<Extension>]
  22.     static member inline When<'TIn>(self: 'TIn, action: Func<'TIn,bool>) =
  23.       new WhenResult<'TIn>(self, action.Invoke self)
  24.    
  25.     [<Extension>]
  26.     static member inline Do<'TIn>(result: WhenResult<'TIn>, action: Action<'TIn>) =
  27.        if result.Status.Positive
  28.        then action.Invoke(result.Value)
  29.        result
  30.    
  31.    [<Extension>]
  32.    static member inline Else<'TIn>(result: WhenResult<'TIn>, action: Func<'TIn,'TIn>) =
  33.        if result.Status.Negative
  34.        then action.Invoke(result.Value)
  35.        else result.Value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement