mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
14 lines
387 B
Swift
14 lines
387 B
Swift
//
|
|
// Optional+ZipWith.swift
|
|
// JSONAPIOpenAPI
|
|
//
|
|
// Created by Mathew Polzin on 1/19/19.
|
|
//
|
|
|
|
/// Zip two optionals together with the given operation performed on
|
|
/// the unwrapped contents. If either optional is nil, the zip
|
|
/// yields nil.
|
|
func zip<X, Y, Z>(_ left: X?, _ right: Y?, with fn: (X, Y) -> Z) -> Z? {
|
|
return left.flatMap { lft in right.map { rght in fn(lft, rght) }}
|
|
}
|