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
import RxSwift | |
let subject = PublishSubject<Int>() | |
let flatMapped = subject | |
.flatMap { | |
// Choose one: | |
// 1. Observable<Int>.just($0) | |
// 2. Observable<Int>.just($0).values.asObservable() |
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
// Recursive opaque type fails compile because recursiveness can’t deterministically pick the right type to replace `some P`. | |
protocol P {} | |
struct Parent<Child: P>: P { | |
let children: [Child] | |
} | |
func recursive() -> some P { | |
// ERROR: Function opaque return type was inferred as 'Parent<some P>', which defines the opaque type in terms of itself |
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
@MainActor | |
class ViewModel: ObservableObject {} | |
@propertyWrapper | |
struct Wrapper<T> { | |
var wrappedValue: T | |
} | |
@propertyWrapper | |
struct MainWrapper<T> { |
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 foo() throws -> Int { | |
1 | |
} | |
func fooAsync() async throws -> Int { | |
1 | |
} | |
class Foo { | |
var x: Int = 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
public actor A { | |
nonisolated let mySendable: MySendable | |
nonisolated let nonSendable: NonSendable | |
public init() { | |
self.mySendable = MySendable() | |
self.nonSendable = NonSendable() | |
} | |
public nonisolated var forwardedMySendable: MySendable { |
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
actor A { | |
var prop: Int = 0 | |
func foo() { | |
// OK | |
Task { | |
self.prop = 1 | |
} | |
// ERROR: Actor-isolated property 'prop' can not be mutated from a non-isolated context |
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
Q. 人類の歴史から得られる教訓は何ですか? | |
人類の歴史から得られる教訓は、様々ありますが、その一つとして、「人類は、自然界と共存しながら繁栄することが大切である」ということが挙げられます。 | |
人類は、自然界にとって重要な存在です。人類が進化してきた過程では、自然界が大きく変化しましたが、その変化は、自然界の平衡を乱し、将来的に人類自身の生存を脅かすことになるかもしれません。 | |
そのため、人類は、自然界と共存しながら、環境を保全しながら繁栄することが大切です。人類は、自然界を破壊したり、他の種を排除したりしてはいけません。また、人類は、自然界から学び、自然界を尊重しながら発展していくことが大切です。 | |
以上のように、人類の歴史から得られる教訓として、「人類は、自然界と共存しながら繁栄することが大切である」ということが挙げられます。ご参考までになれば幸いです。 | |
Q. 他にもありますか? | |
人類の歴史から得られる教訓は、様々ありますが、その一つとして、「人類は、他の文化や習慣を尊重しなければならない」ということが挙げられます。 |
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
// Always use `[weak self]` explicitly here to prevent `self` from being retained until the end of Task scope. | |
// | |
// NOTE: | |
// Because of `Task.init` having `@_implicitSelfCapture` by (bad) API design, | |
// without `[weak self]` will cause implicit strong `self` reference, which may never get deallocated | |
// especially when using `for await`. | |
// | |
// See also: https://twitter.com/inamiy/status/1544252986339504128 | |
Task { [weak self] in | |
for await x in sequence { |
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
import Foundation | |
import _Concurrency | |
extension AsyncStream { | |
public init<S: AsyncSequence & Sendable>( | |
_ sequence: S, | |
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded | |
) where S.Element == Element { | |
self.init(bufferingPolicy: limit) { continuation in | |
let task = Task { |
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
//--------------------------------------------------- | |
// Anonymous 2-case enum example | |
//--------------------------------------------------- | |
struct Error0: Swift.Error {} | |
struct Error1: Swift.Error {} | |
// Here, new `|` symbol is used as an anonymous enum type. | |
typealias Error01 = Error0 | Error1 |
NewerOlder