papply.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. func papply<T1: AnyObject, T2, T3, T4, T5>(weak arg1: T1, _ f: @escaping (T1, T2, T3, T4, T5) -> Void) -> (T2, T3, T4, T5) -> Void {
  2. return { [weak arg1] (arg2: T2, arg3: T3, arg4: T4, arg5: T5) -> Void in
  3. guard let arg1 = arg1
  4. else { return }
  5. f(arg1, arg2, arg3, arg4, arg5)
  6. }
  7. }
  8. func papply<T1: AnyObject, T2, T3, T4>(weak arg1: T1, _ f: @escaping (T1, T2, T3, T4) -> Void) -> (T2, T3, T4) -> Void {
  9. return { [weak arg1] (arg2: T2, arg3: T3, arg4: T4) -> Void in
  10. guard let arg1 = arg1
  11. else { return }
  12. f(arg1, arg2, arg3, arg4)
  13. }
  14. }
  15. func papply<T1: AnyObject, T2, T3>(weak arg1: T1, _ f: @escaping (T1, T2, T3) -> Void) -> (T2, T3) -> Void {
  16. return { [weak arg1] (arg2: T2, arg3: T3) -> Void in
  17. guard let arg1 = arg1
  18. else { return }
  19. f(arg1, arg2, arg3)
  20. }
  21. }
  22. func papply<T1: AnyObject, T2>(weak arg1: T1, _ f: @escaping (T1, T2) -> Void) -> (T2) -> Void {
  23. return { [weak arg1] (arg2: T2) -> Void in
  24. guard let arg1 = arg1
  25. else { return }
  26. f(arg1, arg2)
  27. }
  28. }
  29. func papply<T1: AnyObject>(weak arg1: T1, _ f: @escaping (T1) -> Void) -> () -> Void {
  30. return { [weak arg1] () -> Void in
  31. guard let arg1 = arg1
  32. else { return }
  33. f(arg1)
  34. }
  35. }