ResultExtensions.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // ResultExtensions.swift
  3. //
  4. // Copyright (c) 2016-present, LY Corporation. All rights reserved.
  5. //
  6. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  7. // copy and distribute this software in source code or binary form for use
  8. // in connection with the web services and APIs provided by LY Corporation.
  9. //
  10. // As with any software that integrates with the LY Corporation platform, your use of this software
  11. // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
  12. // This copyright notice shall be included in all copies or substantial portions of the software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  15. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. #if !LineSDKCocoaPods && !LineSDKBinary
  22. import LineSDK
  23. // These helper methods are not public since we do not want them to be exposed or cause any conflicts.
  24. // However, they are just wrapper of `ResultUtil` static methods.
  25. //
  26. // When compiling with CocoaPods, the extensions under LineSDK target should be used.
  27. extension Result {
  28. /// Evaluates the given transform closures to create a single output value.
  29. ///
  30. /// - Parameters:
  31. /// - onSuccess: A closure that transforms the success value.
  32. /// - onFailure: A closure that transforms the error value.
  33. /// - Returns: A single `Output` value.
  34. func match<Output>(
  35. onSuccess: (Success) -> Output,
  36. onFailure: (Failure) -> Output) -> Output
  37. {
  38. return ResultUtil.match(result: self, onSuccess: onSuccess, onFailure: onFailure)
  39. }
  40. func matchSuccess<Output>(with folder: (Success?) -> Output) -> Output {
  41. return ResultUtil.matchSuccess(result: self, with: folder)
  42. }
  43. func matchFailure<Output>(with folder: (Error?) -> Output) -> Output {
  44. return ResultUtil.matchFailure(result: self, with: folder)
  45. }
  46. func match<Output>(with folder: (Success?, Error?) -> Output) -> Output {
  47. return ResultUtil.match(result: self, with: folder)
  48. }
  49. }
  50. #endif