This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefix func ~<A>(_ keyPath: KeyPath<A, Bool>) -> (A) -> Bool { | |
return { $0[keyPath: keyPath] } | |
} | |
// only people with empty street in their address | |
people.filter(~\.address.street.isEmpty) | |
// the names of the people with empty street | |
people.filter(~\.address.street.isEmpty).map(~\.name) | |
// => ["Tom", "Alice", "Bob"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefix func ~<A, B>(_ keyPath: KeyPath<A, B>) -> (A, A) -> Bool where B: Comparable { | |
return { $0[keyPath: keyPath] < $1[keyPath: keyPath] } | |
} | |
// sort in situ, by name | |
var p2 = people | |
p2.sort(by: ~\.name) | |
// people sorted by name | |
people.sorted(by: ~\.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prefix operator ~ | |
prefix func ~<A, B>(_ keyPath: KeyPath<A, B>) -> (A) -> B { | |
return { $0[keyPath: keyPath] } | |
} | |
// list of names for each person | |
people.map(~\.name) | |
// => ["Tom", "Dick", "Harry", "Alice", "Bob", "Charles"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Address { | |
let street: String | |
let city: String | |
let id: String? | |
} | |
struct Person { | |
let name: String | |
let address: Address | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Prefix operator to turn a KeyPath into a function | |
prefix operator ~ | |
/// Allows a key path to be passed into mapping functions | |
/// | |
/// e.g. people.map(~\.name) | |
/// | |
prefix func ~<A, B>(_ keyPath: KeyPath<A, B>) -> (A) -> B { | |
return { $0[keyPath: keyPath] } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sources | |
source 'https://github.com/CocoaPods/Specs.git' | |
# global config | |
platform :ios, '11.0' | |
use_frameworks! | |
workspace 'FunkySocial' | |
# methods to ensure the same version of each library is used across targets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Common | |
import ProfileUI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Workspace | |
version = "1.0"> | |
<FileRef | |
location = “group:FunkySocial/FunkySocial.xcodeproj”> | |
</FileRef> | |
<Group | |
location = “container:” | |
name = “Features”> | |
<FileRef | |
location = “group:NewsFeed/NewsFeed.xcodeproj”> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FileRef | |
location = “group:FunkySocial/FunkySocial.xcodeproj”> | |
</FileRef> | |
<FileRef | |
location = “group:Common/Common.xcodeproj”> | |
</FileRef> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FileRef | |
location = “group:Common/Common.xcodeproj”> | |
</FileRef> | |
<FileRef | |
location = “group:FunkySocial/FunkySocial.xcodeproj”> | |
</FileRef> |