-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setters * Add array-based `concat` functions * Clean up - remove extra concat - remove curried `over`, `set`, `mver`, `mut` - restore `prop` - add `mprop` * small change
- Loading branch information
Showing
12 changed files
with
978 additions
and
465 deletions.
There are no files selected for viewing
File renamed without changes.
70 changes: 70 additions & 0 deletions
70
Overture.playground/Pages/UIKit Setters.xcplaygroundpage/Contents.swift
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Overture | ||
import UIKit | ||
|
||
// Base Styles | ||
|
||
let autolayoutStyle = mut(\UIView.translatesAutoresizingMaskIntoConstraints, false) | ||
|
||
let roundedStyle = concat( | ||
mut(\UIView.clipsToBounds, true), | ||
mut(\.layer.cornerRadius, 6) | ||
) | ||
|
||
func borderStyle(color: UIColor, width: CGFloat) -> (UIView) -> Void { | ||
return concat( | ||
mut(\UIView.layer.borderColor, color.cgColor), | ||
mut(\.layer.borderWidth, width) | ||
) | ||
} | ||
|
||
func buttonFont(_ font: UIFont) -> (UIButton) -> Void { | ||
return { $0.titleLabel?.font = font } | ||
} | ||
|
||
func buttonTitle(_ title: String, for state: UIControlState = .normal) -> (UIButton) -> Void { | ||
return { $0.setTitle(title, for: state) } | ||
} | ||
|
||
func buttonTitleColor(_ color: UIColor, for state: UIControlState = .normal) -> (UIButton) -> Void { | ||
return { $0.setTitleColor(color, for: state) } | ||
} | ||
|
||
// App Styles | ||
|
||
let baseButtonStyle: (UIButton) -> Void = concat( | ||
mut(\.contentEdgeInsets, .init(top: 12, left: 16, bottom: 12, right: 16)), | ||
buttonFont(.systemFont(ofSize: 16)) | ||
) | ||
|
||
let roundButtonStyle = concat( | ||
baseButtonStyle, | ||
roundedStyle | ||
) | ||
|
||
let filledButtonStyle = concat( | ||
roundButtonStyle, | ||
mut(\.backgroundColor, .black), | ||
mut(\.tintColor, .white) | ||
) | ||
|
||
let borderButtonStyle = concat( | ||
roundButtonStyle, | ||
borderStyle(color: .black, width: 2), | ||
buttonTitleColor(.black) | ||
) | ||
|
||
let nextButton = with( | ||
UIButton(), | ||
concat( | ||
filledButtonStyle, | ||
buttonTitle("Next") | ||
) | ||
) | ||
|
||
let cancelButton = with( | ||
UIButton(), | ||
concat( | ||
borderButtonStyle, | ||
buttonTitle("Cancel") | ||
) | ||
) |
29 changes: 29 additions & 0 deletions
29
Overture.playground/Pages/URLRequest Setters - Immutable.xcplaygroundpage/Contents.swift
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
import Overture | ||
|
||
let guaranteeHeaders = over(\URLRequest.allHTTPHeaderFields) { $0 ?? [:] } | ||
|
||
let setHeader = { name, value in | ||
concat( | ||
guaranteeHeaders, | ||
set(compose(prop(\.allHTTPHeaderFields), map, prop(\.[name])), value) | ||
) | ||
} | ||
|
||
let postJson = concat( | ||
set(\.httpMethod, "POST"), | ||
setHeader("Content-Type", "application/json; charset=utf-8") | ||
) | ||
|
||
let gitHubAccept = setHeader("Accept", "application/vnd.github.v3+json") | ||
|
||
let attachAuthorization = { token in setHeader("Authorization", "Token " + token) } | ||
|
||
let request = with( | ||
URLRequest(url: URL(string: "https://www.pointfree.co/hello")!), | ||
concat( | ||
attachAuthorization("deadbeef"), | ||
gitHubAccept, | ||
postJson | ||
) | ||
) |
26 changes: 26 additions & 0 deletions
26
Overture.playground/Pages/URLRequest Setters - Mutable.xcplaygroundpage/Contents.swift
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import Overture | ||
|
||
let guaranteeHeaders = mver(\URLRequest.allHTTPHeaderFields) { $0 = $0 ?? [:] } | ||
|
||
let setHeader = { name, value in | ||
concat(guaranteeHeaders) { $0.allHTTPHeaderFields?[name] = value } | ||
} | ||
|
||
let postJson = concat( | ||
mut(\.httpMethod, "POST"), | ||
setHeader("Content-Type", "application/json; charset=utf-8") | ||
) | ||
|
||
let gitHubAccept = setHeader("Accept", "application/vnd.github.v3+json") | ||
|
||
let attachAuthorization = { token in setHeader("Authorization", "Token " + token) } | ||
|
||
let request = with( | ||
URLRequest(url: URL(string: "https://www.pointfree.co/hello")!), | ||
concat( | ||
attachAuthorization("deadbeef"), | ||
gitHubAccept, | ||
postJson | ||
) | ||
) |
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,2 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='6.0' target-platform='macos'/> | ||
<playground version='6.0' target-platform='ios' executeOnSourceChanges='false'> | ||
<pages> | ||
<page name='Basics'/> | ||
<page name='UIKit Setters'/> | ||
<page name='URLRequest Setters - Immutable'/> | ||
<page name='URLRequest Setters - Mutable'/> | ||
</pages> | ||
</playground> |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.