-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
352 additions
and
523 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,67 @@ | ||
import Foundation | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month)> {} | ||
public extension TypedDate<(Year, Month)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_MonthEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _MonthEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month, Day)> {} | ||
public extension TypedDate<(Year, Month, Day)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_DayEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _DayEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month, Day, Hour)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_HourEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _HourEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_MinuteEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _MinuteEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_SecondEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _SecondEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} | ||
|
||
@EraseContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second, Nanosecond)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second, Nanosecond)> { | ||
func erase<T>( | ||
to keyPath: KeyPath<_NanosecondEraseContext, (TypedDate<T>.Type, T)>, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _NanosecondEraseContext(base: components) [keyPath: keyPath] | ||
return context.0.init(context.1, calendar: calendar) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,79 @@ | ||
import Foundation | ||
|
||
@FillInContext | ||
public extension TypedDate<Year> {} | ||
public extension TypedDate<Year> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_YearFillInContext,(U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _YearFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} | ||
|
||
@FillInContext | ||
public extension TypedDate<(Year, Month)> {} | ||
public extension TypedDate<(Year, Month)> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_MonthFillInContext,(U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _MonthFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} | ||
|
||
@FillInContext | ||
public extension TypedDate<(Year, Month, Day)> {} | ||
public extension TypedDate<(Year, Month, Day)> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_DayFillInContext, (U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _DayFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} | ||
|
||
@FillInContext | ||
public extension TypedDate<(Year, Month, Day, Hour)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour)> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_HourFillInContext, (U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _HourFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} | ||
|
||
@FillInContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_MinuteFillInContext, (U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _MinuteFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} | ||
|
||
@FillInContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> { | ||
func fill<T, U>( | ||
to keyPath: KeyPath<_SecondFillInContext, (U) -> T>, | ||
arguments: U, | ||
calendar: Calendar = .current | ||
) -> TypedDate<T> { | ||
let context = _SecondFillInContext(base: components) | ||
let transform = context[keyPath: keyPath] | ||
return .init(transform(arguments), calendar: calendar) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,181 @@ | ||
import Foundation | ||
|
||
/// Extension for `TypedDate<Year>`. Allows for modifying the year component of a date. | ||
@ModifyContext | ||
public extension TypedDate<Year> {} | ||
public extension TypedDate<Year> { | ||
/// Modifies the year component of `TypedDate<Year>` with a provided modification closure. | ||
/// - Parameters: | ||
/// - keyPath: KeyPath to the year modify context. | ||
/// - modify: Closure that takes an inout parameter of type T for modification. | ||
/// - calendar: Calendar used for date calculations, defaults to the current calendar. | ||
/// - Returns: A new `TypedDate<Components>` instance with modified year component. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_YearModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _YearModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year component of `TypedDate<Year>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_YearModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year' and 'Month'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month)> {} | ||
public extension TypedDate<(Year, Month)> { | ||
/// Modifies the year and month components of `TypedDate<Year, Month>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_MonthModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _MonthModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year and month components of `TypedDate<Year, Month>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_MonthModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year', 'Month', and 'Day'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month, Day)> {} | ||
public extension TypedDate<(Year, Month, Day)> { | ||
/// Modifies the year, month, and day components of `TypedDate<Year, Month, Day>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_DayModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _DayModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year, month, and day components of `TypedDate<Year, Month, Day>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_DayModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year', 'Month', 'Day', and 'Hour'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month, Day, Hour)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour)> { | ||
/// Modifies the year, month, day, and hour components of `TypedDate<Year, Month, Day, Hour>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_HourModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _HourModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year, month, day, and hour components of `TypedDate<Year, Month, Day, Hour>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_HourModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year', 'Month', 'Day', 'Hour', and 'Minute'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute)> { | ||
/// Modifies the year, month, day, hour, and minute components of `TypedDate<Year, Month, Day, Hour, Minute>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_MinuteModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _MinuteModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year, month, day, hour, and minute components of `TypedDate<Year, Month, Day, Hour, Minute>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_MinuteModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year', 'Month', 'Day', 'Hour', 'Minute', and 'Second'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second)> { | ||
/// Modifies the year, month, day, hour, minute, and second components of `TypedDate<Year, Month, Day, Hour, Minute, Second>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_SecondModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _SecondModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year, month, day, hour, minute, and second components of `TypedDate<Year, Month, Day, Hour, Minute, Second>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_SecondModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} | ||
|
||
/// Extension for `TypedDate` combining 'Year', 'Month', 'Day', 'Hour', 'Minute', 'Second', and 'Nanosecond'. | ||
@ModifyContext | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second, Nanosecond)> {} | ||
public extension TypedDate<(Year, Month, Day, Hour, Minute, Second, Nanosecond)> { | ||
/// Modifies the year, month, day, hour, minute, second, and nanosecond components of `TypedDate<Year, Month, Day, Hour, Minute, Second, Nanosecond>` with a provided modification closure. | ||
func modifying<T>( | ||
_ keyPath: KeyPath<_NanosecondModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) -> TypedDate<Components> { | ||
let context = _NanosecondModifyContext(base: components) | ||
var (target, transform) = context[keyPath: keyPath] | ||
modify(&target) | ||
return .init(transform(target), calendar: calendar) | ||
} | ||
|
||
/// Mutates the year, month, day, hour, minute, second, and nanosecond components of `TypedDate<Year, Month, Day, Hour, Minute, Second, Nanosecond>` instance. | ||
mutating func modify<T>( | ||
_ keyPath: KeyPath<_NanosecondModifyContext, (T, (T) -> Components)>, | ||
calendar: Calendar = .current, | ||
modify: (inout T) -> Void | ||
) { | ||
self = modifying(keyPath, calendar: calendar, modify: modify) | ||
} | ||
} |
Oops, something went wrong.