-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCurried_ObjectWithNoMetadata.swift
More file actions
84 lines (71 loc) · 2.45 KB
/
Curried_ObjectWithNoMetadata.swift
File metadata and controls
84 lines (71 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Curried_ObjectWithNoMetadata.swift
// YapDatabaseExtensions
//
// Created by Daniel Thorpe on 14/10/2015.
//
//
import Foundation
import ValueCoding
// MARK: - Persistable
extension Persistable where
Self: NSCoding,
Self.MetadataType == Void {
/**
Returns a closure which, given a read transaction will return
the item at the given index.
- parameter index: a YapDB.Index
- returns: a (ReadTransaction) -> Self? closure.
*/
public static func readAtIndex<
ReadTransaction where
ReadTransaction: ReadTransactionType>(index: YapDB.Index) -> ReadTransaction -> Self? {
return { $0.readAtIndex(index) }
}
/**
Returns a closure which, given a read transaction will return
the items at the given indexes.
- parameter indexes: a SequenceType of YapDB.Index values
- returns: a (ReadTransaction) -> [Self] closure.
*/
public static func readAtIndexes<
Indexes, ReadTransaction where
Indexes: SequenceType,
Indexes.Generator.Element == YapDB.Index,
ReadTransaction: ReadTransactionType>(indexes: Indexes) -> ReadTransaction -> [Self] {
return { $0.readAtIndexes(indexes) }
}
/**
Returns a closure which, given a read transaction will return
the item at the given key.
- parameter key: a String
- returns: a (ReadTransaction) -> Self? closure.
*/
public static func readByKey<
ReadTransaction where
ReadTransaction: ReadTransactionType>(key: String) -> ReadTransaction -> Self? {
return { $0.readByKey(key) }
}
/**
Returns a closure which, given a read transaction will return
the items at the given keys.
- parameter keys: a SequenceType of String values
- returns: a (ReadTransaction) -> [Self] closure.
*/
public static func readByKeys<
Keys, ReadTransaction where
Keys: SequenceType,
Keys.Generator.Element == String,
ReadTransaction: ReadTransactionType>(keys: Keys) -> ReadTransaction -> [Self] {
return { $0.readAtIndexes(Self.indexesWithKeys(keys)) }
}
/**
Returns a closure which, given a write transaction will write
and return the item.
- warning: Be aware that this will capure `self`.
- returns: a (WriteTransaction) -> Self closure
*/
public func write<WriteTransaction: WriteTransactionType>() -> WriteTransaction -> Self {
return { $0.write(self) }
}
}