Module ngx-oauth.either

The Either monad.

The Either type represents values with two possibilities: a value of type Either a b is either a Left, whose value is of type a, or a Right, whose value is of type b. The Either itself is not needed in this implementation, so you find only Left and Right here.

This implementation (hopefully) satisfies Monad specification from the Fantasy Land Specification, except the of method. Instead of Left.of(a) and Right.of(a), use Left(a) and Right(a).

Functions

Left (value) Returns a Left with the given value.
Left.ap () Returns self.
Left.map () Returns self.
Left.chain () Returns self.
Right (value) Returns a Right with the given value.
Right.ap (either) Returns a Right whose value is the result of applying self's value to the given Right's value, if it's Right; otherwise returns the given Left.
Right.map (func) Returns a Right whose value is the result of applying the func to this Right's value.
Right.chain (func) Returns the result of applying the given function to self's value.
either (on_left, on_right, teither) Returns the result of applying the on_left function to the Left's value, if the teither is a Left, or the result of applying the on_right function to the Right's value, if the teither is a Right.
encase (func) Adapts the given function, that may throw an error, to return either Left with the error message, or Right with the result.
encase2 (func) Adapts the given function, that returns nil,err on failure and res,nil on success, to return either Left with err, or Right with res.
__call () An alias for either.


Functions

Left (value)
Returns a Left with the given value.

Parameters:

  • value The value of any type to wrap.

Returns:

    Left
Left.ap ()
Returns self.

Returns:

    Left self
Left.map ()
Returns self.

Returns:

    Left self
Left.chain ()
Returns self.

Returns:

    Left self
Right (value)
Returns a Right with the given value.

Parameters:

  • value The value of any type to wrap.

Returns:

    Right
Right.ap (either)
Returns a Right whose value is the result of applying self's value to the given Right's value, if it's Right; otherwise returns the given Left.

Parameters:

Returns:

    any

Raises:

Error if self's value is not a function or if either is not Left, nor Right.
Right.map (func)
Returns a Right whose value is the result of applying the func to this Right's value.

Parameters:

  • func function

Returns:

    Right
Right.chain (func)
Returns the result of applying the given function to self's value.

Parameters:

  • func function

Returns:

    any
either (on_left, on_right, teither)
Returns the result of applying the on_left function to the Left's value, if the teither is a Left, or the result of applying the on_right function to the Right's value, if the teither is a Right.

Parameters:

  • on_left function The Left's handler.
  • on_right function The Right's handler.
  • teither Left or Right

Raises:

Error when teither is not Left, nor Right.
encase (func)
Adapts the given function, that may throw an error, to return either Left with the error message, or Right with the result.

Parameters:

  • func function The function to adapt.

Returns:

    function An adapted func that accepts the same arguments as func, but returns Left on an error and Right on a success.
encase2 (func)
Adapts the given function, that returns nil,err on failure and res,nil on success, to return either Left with err, or Right with res.

Parameters:

  • func function The function to adapt.

Returns:

    function An adapted func that accepts the same arguments as func, but returns Left on an error and Right on a success.
__call ()
An alias for either.
generated by LDoc 1.4.3