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
func curry<A, B, C>(f: (A, B) -> C) -> A -> B -> C { | |
return { a in { b in f(a, b) } } | |
} | |
let add = curry(+) | |
let xs = 1...100 | |
let x = xs.map(add(2)) // [3, 4, 5, 6, etc] |
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
infix operator |> { precedence 50 associativity left } | |
// Pipe forward: transform "x |> f" to "f(x)" and "x |> f |> g |> h" to "h(g(f(x)))" | |
public func |> <T,U>(lhs: T, rhs: T -> U) -> U { | |
return rhs(lhs) | |
} | |
//Without the forward pipe | |
let convertedImage = convertToGrayscale(image: adjustColors(image: image)) |
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
struct User { | |
let name: String? | |
let surname: String? | |
let nickname: String? | |
} | |
//Our goal is to build a human-readable string in a: | |
//Name Surname, "Nickname" | |
//format. | |
//The example output would be: |
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
struct Novella { | |
let name: String | |
} | |
struct Novellas { | |
let novellas: [Novella] | |
} | |
struct NovellasIterator: IteratorProtocol { |
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
{ | |
"bannerCategory":{ | |
"name":"", | |
"apps":[ | |
{ | |
"ImageName":"enhancedWith3dTouch" | |
}, | |
{ | |
"ImageName":"drSeussBanner" | |
}, |
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
{ | |
"stream_url":"http://184.72.239.149/vod/smil:BigBuckBunny.smil/playlist.m3u8", | |
"main_title":"", | |
"second_title":"", | |
"preview_image":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTPsJRF7eUSmp5z8r76MxwR1MEn3l7H_L1OaAjkFOfowOC87RCJyQ", | |
"type":"", | |
"thumbnails":[ | |
{ | |
"count_x":"0", | |
"count_y":"0", |
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
{ | |
"main_title": "عنوان اصلی", | |
"second_title": "عنوان فرعی", | |
"type": "vod", | |
"stream_url": "", | |
"thumbnails": [ | |
{ | |
"count_x": 5, | |
"count_y": 5, | |
"width": 160, |
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
enum HTTPMethod: String { | |
case get = "GET" | |
} | |
class HTTPLayer { | |
let baseURL = URL(string: "https://hamed-gh.com")! | |
func request(at endpoint: Endpoint, completion: @escaping (Data?, Error?) -> Void) { | |
let url = baseURL.appendingPathComponent(endpoint.path) |
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
//A standard phone number pad has the following layout. | |
//1 2 3 | |
//4 5 6 | |
//7 8 9 | |
// 0 | |
//Using this layout and a starting digit we can generate numbers as follows: The first digit is the | |
//starting digit and each subsequent digit is directly left, right, above or below the previous digit on | |
//the number pad. For example if the starting digit is 1, 1256 is a valid number, but 1289 is not | |
//valid because 8 is not directly next to 2. Write a function that takes a starting digit d and an | |
//integer n as input and returns a list of all unique numbers of length n generated in this way. |