Skip to content

Commit

Permalink
extend array to filter only the first element
Browse files Browse the repository at this point in the history
  • Loading branch information
Imthath M committed May 28, 2019
1 parent 5039ed1 commit 4ff2096
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
4 changes: 0 additions & 4 deletions UtilitiesExample/UtilitiesExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
A8B6EA18224CCCF800A765A3 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA17224CCCF800A765A3 /* main.swift */; };
A8B6EA23224CCD3D00A765A3 /* FileIO.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA1E224CCD3D00A765A3 /* FileIO.swift */; };
A8B6EA24224CCD3D00A765A3 /* OptionalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA1F224CCD3D00A765A3 /* OptionalExtension.swift */; };
A8B6EA25224CCD3D00A765A3 /* EquatableExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA20224CCD3D00A765A3 /* EquatableExtension.swift */; };
A8B6EA26224CCD3D00A765A3 /* CodableExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA21224CCD3D00A765A3 /* CodableExtensions.swift */; };
A8B6EA27224CCD3D00A765A3 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA22224CCD3D00A765A3 /* DateExtension.swift */; };
A8B6EA2A224CD03E00A765A3 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B6EA29224CD03E00A765A3 /* StringExtension.swift */; };
Expand All @@ -39,7 +38,6 @@
A8B6EA17224CCCF800A765A3 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
A8B6EA1E224CCD3D00A765A3 /* FileIO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileIO.swift; sourceTree = "<group>"; };
A8B6EA1F224CCD3D00A765A3 /* OptionalExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptionalExtension.swift; sourceTree = "<group>"; };
A8B6EA20224CCD3D00A765A3 /* EquatableExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EquatableExtension.swift; sourceTree = "<group>"; };
A8B6EA21224CCD3D00A765A3 /* CodableExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableExtensions.swift; sourceTree = "<group>"; };
A8B6EA22224CCD3D00A765A3 /* DateExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
A8B6EA29224CD03E00A765A3 /* StringExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -87,7 +85,6 @@
children = (
A8B6EA21224CCD3D00A765A3 /* CodableExtensions.swift */,
A8B6EA22224CCD3D00A765A3 /* DateExtension.swift */,
A8B6EA20224CCD3D00A765A3 /* EquatableExtension.swift */,
A8B6EA1E224CCD3D00A765A3 /* FileIO.swift */,
A8B6EA1F224CCD3D00A765A3 /* OptionalExtension.swift */,
A8B6EA29224CD03E00A765A3 /* StringExtension.swift */,
Expand Down Expand Up @@ -178,7 +175,6 @@
files = (
A82595552296B28E000F1BF4 /* UUIDextension.swift in Sources */,
A859C9A2225DCE8400CFFC71 /* Vehicle.swift in Sources */,
A8B6EA25224CCD3D00A765A3 /* EquatableExtension.swift in Sources */,
A8B6EA2A224CD03E00A765A3 /* StringExtension.swift in Sources */,
A81A1DA92264924A002FCAA5 /* ArrayExtension.swift in Sources */,
A8B6EA27224CCD3D00A765A3 /* DateExtension.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions UtilitiesExample/Utils/ArrayExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ extension Array where Element: Equatable {
}

extension Array {

/// returns the first element which satisfies the given condition
public func filterFirst(_ condition: (Element) throws -> Bool) rethrows -> Element? {
for element in self where try condition(element) {
return element
}

return nil
}

mutating public func appendOptional(_ newElement: Element?) {
if let element = newElement {
self.append(element)
Expand Down
17 changes: 0 additions & 17 deletions UtilitiesExample/Utils/EquatableExtension.swift

This file was deleted.

0 comments on commit 4ff2096

Please sign in to comment.