This file contains hidden or 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
(defn merge-maps [& maps] | |
;; (sanitize-map) | |
(if (every? map? maps) | |
(apply merge-with merge-maps maps) | |
(last maps))) | |
(defn sanitize-map [m] | |
(if (map? m) | |
(let [clean-val (fn [[k v]] | |
(let [v' (sanitize-map v)] |
This file contains hidden or 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
import Foundation | |
// today coding: write a reversed value semantic enum list. | |
indirect enum List<T> { | |
case empty | |
case node(T, List<T>) | |
} | |
extension List { |
This file contains hidden or 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
indirect enum List<T> { | |
case empty | |
case node(T, List<T>) | |
var value: T? { | |
if case .node(let value, _) = self { | |
return value | |
} else { | |
return nil | |
} |
This file contains hidden or 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
import Foundation | |
// today coding: implement map filter reduce of the value semantic enum list. | |
indirect enum List<T> { | |
case empty | |
case node(T, List<T>) | |
} | |
extension List { |
This file contains hidden or 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
import SwiftUI | |
// today coding: async sequence in Swift | |
struct URLSequence: AsyncSequence { | |
typealias AsyncIterator = URLIterator | |
typealias Element = Data | |
let urls: [URL] | |
This file contains hidden or 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
import Foundation | |
// daily coding 2022/05/06 | |
// seven ways to solve fibonnaci in Swift. | |
// (0) imperative style | |
// (1) using any sequence and iterator | |
// (2) normal recursion version | |
// (3) shorter recursion version |
This file contains hidden or 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
let res4 = Array( | |
AnySequence { () -> AnyIterator<Int> in | |
var t1 = (0, 1) | |
return AnyIterator<Int> { | |
let (a, b) = t1 | |
t1 = (b, a + b) | |
return b | |
} | |
} | |
.prefix(10) |
This file contains hidden or 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
import Foundation | |
struct Recursion { | |
/// Generate `a growing closure` to keep track of the all of history of task, and | |
/// run a function as a given parameter after executing all of previous tasks if tasks exist, and add the function to the tasks. | |
/// - Returns: `the growing closure` to remember the tasks to execute. | |
/// | |
/// ``` | |
/// let recur = Recursion.generateGrowingClosure() |
This file contains hidden or 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
import Foundation | |
struct Recursion { | |
static func generated() | |
-> ((() -> Void)?) -> () | |
{ | |
var tasks: [(() -> ())?] = [] | |
let closure = { (task: (() -> Void)?) in | |
tasks.append(task) |
This file contains hidden or 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
import Foundation | |
struct Recursion { | |
static func recur(task baseTask: @escaping () -> Void, | |
willGrow: Bool = true) | |
-> (( () -> Void)?) -> Void | |
{ | |
var next = 0 | |
return { lastTask in |