Skip to content

Instantly share code, notes, and snippets.

View samdods's full-sized avatar

Sam Dods samdods

  • The App Business
  • London
View GitHub Profile
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"]
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)
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"]
struct Address {
let street: String
let city: String
let id: String?
}
struct Person {
let name: String
let address: Address
}
/// 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] }
}
# 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
import UIKit
import Common
import ProfileUI
<Workspace
version = "1.0">
<FileRef
location = “group:FunkySocial/FunkySocial.xcodeproj”>
</FileRef>
<Group
location = “container:”
name = “Features”>
<FileRef
location = “group:NewsFeed/NewsFeed.xcodeproj”>
<FileRef
location = “group:FunkySocial/FunkySocial.xcodeproj”>
</FileRef>
<FileRef
location = “group:Common/Common.xcodeproj”>
</FileRef>
<FileRef
location = “group:Common/Common.xcodeproj”>
</FileRef>
<FileRef
location = “group:FunkySocial/FunkySocial.xcodeproj”>
</FileRef>