Skip to content

Commit

Permalink
Adding unpack to sequence extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaal111 committed Apr 27, 2024
1 parent 2affdc5 commit a5e3446
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/KamaalExtensions/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ extension Sequence {
try first(where: predicate)
}

/// Unpacks items in the sequence to only contain non optional values.
/// - Returns: An array without optionals.
public func unpacked<T>() -> [T] where Element == T? {
compactMap { $0 }
}

/// Group results in to a tuple of successes and failures.
/// - Returns: A tuple of successes and failures.
public func grouped<Success, Failure: Error>() -> (
Expand Down

0 comments on commit a5e3446

Please sign in to comment.