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 | |
// < iOS 16 | |
var task: Task<(), Never>? | |
func delay(seconds: Int = 1, | |
operation: @escaping () -> Void) { | |
task = Task { | |
do { |
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 | |
// reference: https://stackoverflow.com/questions/67978028/maximum-number-of-threads-with-async-await-task-groups | |
func run() async { | |
await withTaskGroup(of: Void.self) { group in | |
for i in 0 ..< 32 { | |
group.addTask { | |
print(await fire(i)) | |
} |
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 | |
// >= iOS 16 | |
var task: Task<(), Never>? | |
func delay(interval: Duration = .seconds(1), | |
operation: @escaping () -> Void) { | |
task = Task { | |
do { |
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 | |
// >= iOS 16 | |
var task: Task<(), Never>? | |
func debounce(interval: Duration = .nanoseconds(10000), | |
operation: @escaping () -> Void) { | |
task?.cancel() |
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
// | |
// debounce-throttle.swift | |
// | |
// Created by Simon Ljungberg on 19/12/16. | |
// License: MIT | |
// | |
import Foundation | |
extension TimeInterval { |
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 | |
precedencegroup ForwardPipe { | |
associativity: left | |
} | |
infix operator |> : ForwardPipe | |
func |> <V, F>(v: V, f: ((V) -> F)) -> F { | |
f(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
export default "123"; |
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
;; Clojure macro & homoiconicity (LISP) for newbies | |
;; | |
;; This is personal study note | |
;; | |
;; Disclaimer: | |
;; Here I am trying to guide the high level of overview of macro & homoiconicity based on Clojure. | |
;; I cannot say these will be 100% accurate, since I am also still in the middle of getting LISP and Clojure, | |
;; but at least I believe it could portray the big picture | |
;; rather than the technical detail inside, providing links of blogs and articles I found useful. | |
;; Please do your own research when in doubt if interested further by using this as the guidance. |
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
;; invert binary tree: https://leetcode.com/problems/invert-binary-tree/ | |
;; Given the root of a binary tree, invert the tree, and return its root. | |
;; Input: root = [4,2,7,1,3,6,9] | |
;; Output: [4,7,2,9,6,3,1] | |
;; Input: root = [2,1,3] | |
;; Output: [2,3,1] | |
;; Input: root = [] |
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
;; The Pascal Triangle: https://www.hackerrank.com/challenges/pascals-triangle/problem?isFullScreen=true | |
;; For a given integer , print the first rows of Pascal's Triangle. | |
;; Print each row with each value separated by a single space. | |
;; The value at the row and column of the triangle is equal to where indexing starts from. | |
;; These values are the binomial coefficients. | |
;; The Pascal Triangle | |
;; 1 | |
;; 1 1 |