@swiftbrowser/swift 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/Package.swift +200 -9
  2. package/README.md +7 -9
  3. package/Sources/AVFoundation/AVFoundation.swift +131 -0
  4. package/Sources/AVFoundation/Asset.swift +487 -0
  5. package/Sources/AVFoundation/AudioSession.swift +144 -0
  6. package/Sources/AVFoundation/CMTime.swift +303 -0
  7. package/Sources/AVFoundation/Capture.swift +688 -0
  8. package/Sources/AVFoundation/Player.swift +749 -0
  9. package/Sources/AVFoundation/PlayerView.swift +117 -0
  10. package/Sources/AVKit/AVKit.swift +132 -0
  11. package/Sources/Accelerate/Accelerate.swift +122 -0
  12. package/Sources/AppIntents/AppIntents.swift +144 -0
  13. package/Sources/AppIntents/Parameters.swift +220 -0
  14. package/Sources/AppIntents/Shortcuts.swift +159 -0
  15. package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
  16. package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
  17. package/Sources/AuthenticationServices/Authorization.swift +251 -0
  18. package/Sources/Charts/Charts.swift +0 -4
  19. package/Sources/Combine/AnyCancellable.swift +65 -0
  20. package/Sources/Combine/AnyPublisher.swift +148 -0
  21. package/Sources/Combine/AnySubscriber.swift +230 -0
  22. package/Sources/Combine/Cancellable.swift +35 -0
  23. package/Sources/Combine/Codable.swift +29 -0
  24. package/Sources/Combine/CombineIdentifier.swift +45 -0
  25. package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
  26. package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
  27. package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
  28. package/Sources/Combine/CurrentValueSubject.swift +252 -0
  29. package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
  30. package/Sources/Combine/Future.swift +228 -0
  31. package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
  32. package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
  33. package/Sources/Combine/Helpers/ConduitList.swift +59 -0
  34. package/Sources/Combine/Helpers/DebugHook.swift +177 -0
  35. package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
  36. package/Sources/Combine/Helpers/Locking.swift +30 -0
  37. package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
  38. package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
  39. package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
  40. package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
  41. package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
  42. package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
  43. package/Sources/Combine/Helpers/Utils.swift +30 -0
  44. package/Sources/Combine/Helpers/Violations.swift +33 -0
  45. package/Sources/Combine/ImmediateScheduler.swift +178 -0
  46. package/Sources/Combine/LICENSE +21 -0
  47. package/Sources/Combine/NotificationPublisher.swift +48 -0
  48. package/Sources/Combine/ObjectWillChange.swift +46 -0
  49. package/Sources/Combine/PassthroughSubject.swift +222 -0
  50. package/Sources/Combine/Publisher+Subscribe.swift +53 -0
  51. package/Sources/Combine/Publishers/Deferred.swift +48 -0
  52. package/Sources/Combine/Publishers/Empty.swift +54 -0
  53. package/Sources/Combine/Publishers/Fail.swift +42 -0
  54. package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
  55. package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
  56. package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
  57. package/Sources/Combine/Publishers/Just.swift +313 -0
  58. package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
  59. package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
  60. package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
  61. package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
  62. package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
  63. package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
  64. package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
  65. package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
  66. package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
  67. package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
  68. package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
  69. package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
  70. package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
  71. package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
  72. package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
  73. package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
  74. package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
  75. package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
  76. package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
  77. package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
  78. package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
  79. package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
  80. package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
  81. package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
  82. package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
  83. package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
  84. package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
  85. package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
  86. package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
  87. package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
  88. package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
  89. package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
  90. package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
  91. package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
  92. package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
  93. package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
  94. package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
  95. package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
  96. package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
  97. package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
  98. package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
  99. package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
  100. package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
  101. package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
  102. package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
  103. package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
  104. package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
  105. package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
  106. package/Sources/Combine/Publishers/Publishers.swift +13 -0
  107. package/Sources/Combine/Publishers/Record.swift +237 -0
  108. package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
  109. package/Sources/Combine/Result.swift +46 -0
  110. package/Sources/Combine/Scheduler.swift +89 -0
  111. package/Sources/Combine/Schedulers.swift +211 -0
  112. package/Sources/Combine/Subject+Void.swift +17 -0
  113. package/Sources/Combine/Subscriber+Void.swift +20 -0
  114. package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
  115. package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
  116. package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
  117. package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
  118. package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
  119. package/Sources/Combine/Subscription.swift +22 -0
  120. package/Sources/Combine/Subscriptions.swift +42 -0
  121. package/Sources/Combine/SwiftUIObservation.swift +10 -0
  122. package/Sources/Combine/_Introspection.swift +107 -0
  123. package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
  124. package/Sources/Compression/Compression.swift +365 -0
  125. package/Sources/Compression/Deflate.swift +407 -0
  126. package/Sources/Compression/Zlib.swift +179 -0
  127. package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
  128. package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
  129. package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
  130. package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
  131. package/Sources/CoreImage/CIColor.swift +41 -0
  132. package/Sources/CoreImage/CIContext.swift +31 -0
  133. package/Sources/CoreImage/CIDetector.swift +57 -0
  134. package/Sources/CoreImage/CIFilter.swift +243 -0
  135. package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
  136. package/Sources/CoreImage/CIImage.swift +162 -0
  137. package/Sources/CoreImage/QRCode.swift +393 -0
  138. package/Sources/CoreLocation/Coordinate.swift +30 -0
  139. package/Sources/CoreLocation/Location.swift +65 -0
  140. package/Sources/CoreML/Evaluation.swift +414 -0
  141. package/Sources/CoreML/FeatureValue.swift +266 -0
  142. package/Sources/CoreML/Model.swift +269 -0
  143. package/Sources/CoreML/MultiArray.swift +92 -0
  144. package/Sources/CoreML/Specification.swift +233 -0
  145. package/Sources/CoreText/CoreText.swift +64 -0
  146. package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
  147. package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
  148. package/Sources/CryptoKit/CryptoKit.swift +375 -0
  149. package/Sources/CryptoKit/Curve25519.swift +317 -0
  150. package/Sources/CryptoKit/P256.swift +321 -0
  151. package/Sources/FoundationBridge/AppStorage.swift +165 -0
  152. package/Sources/FoundationBridge/AssetResources.swift +90 -0
  153. package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
  154. package/Sources/FoundationBridge/AsyncImage.swift +116 -0
  155. package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
  156. package/Sources/{_FoundationCommon → FoundationBridge}/Bundle.swift +41 -4
  157. package/Sources/FoundationBridge/CombineExports.swift +8 -0
  158. package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
  159. package/Sources/FoundationBridge/Dispatch.swift +458 -0
  160. package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
  161. package/Sources/FoundationBridge/FileImporter.swift +128 -0
  162. package/Sources/FoundationBridge/FileSystem.swift +68 -0
  163. package/Sources/FoundationBridge/FoundationBridge.swift +24 -72
  164. package/Sources/FoundationBridge/HostResolution.swift +31 -0
  165. package/Sources/FoundationBridge/ItemProvider.swift +655 -0
  166. package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
  167. package/Sources/FoundationBridge/Links.swift +127 -0
  168. package/Sources/FoundationBridge/ListFormatter.swift +32 -0
  169. package/Sources/FoundationBridge/Localization.swift +149 -0
  170. package/Sources/FoundationBridge/Locks.swift +50 -0
  171. package/Sources/FoundationBridge/Markdown.swift +527 -0
  172. package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
  173. package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
  174. package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
  175. package/Sources/FoundationBridge/Operation.swift +195 -0
  176. package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
  177. package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
  178. package/Sources/FoundationBridge/SceneStorage.swift +78 -0
  179. package/Sources/FoundationBridge/SecurityExports.swift +8 -0
  180. package/Sources/FoundationBridge/Selector.swift +226 -0
  181. package/Sources/FoundationBridge/StringComparators.swift +17 -0
  182. package/Sources/FoundationBridge/Table.swift +211 -0
  183. package/Sources/FoundationBridge/TextAttributes.swift +42 -0
  184. package/Sources/FoundationBridge/Timer.swift +6 -1
  185. package/Sources/FoundationBridge/URLSession.swift +718 -0
  186. package/Sources/{_FoundationCommon → FoundationBridge}/UserDefaults.swift +17 -4
  187. package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
  188. package/Sources/FoundationBridge/WebSocket.swift +187 -0
  189. package/Sources/FoundationModels/FoundationModels.swift +1098 -0
  190. package/Sources/ImageIO/GIF.swift +72 -0
  191. package/Sources/ImageIO/ImageIO.swift +248 -0
  192. package/Sources/ImageIO/ImageTypes.swift +28 -0
  193. package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
  194. package/Sources/LocalAuthentication/LAContext.swift +86 -0
  195. package/Sources/MapKit/Geometry.swift +223 -0
  196. package/Sources/MapKit/Map.swift +638 -0
  197. package/Sources/MapKit/MapView.swift +229 -0
  198. package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
  199. package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
  200. package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
  201. package/Sources/OSLog/OSLog.swift +6 -0
  202. package/Sources/Photos/Photos.swift +572 -0
  203. package/Sources/PhotosUI/PhotosPicker.swift +248 -0
  204. package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
  205. package/Sources/QuickLook/QuickLook.swift +168 -0
  206. package/Sources/SafariServices/SafariServices.swift +106 -0
  207. package/Sources/Security/Security.swift +332 -0
  208. package/Sources/StoreKit/AppStore.swift +207 -0
  209. package/Sources/StoreKit/Products.swift +280 -0
  210. package/Sources/StoreKit/RequestReview.swift +28 -0
  211. package/Sources/StoreKit/StoreKit1.swift +486 -0
  212. package/Sources/StoreKit/StoreViews.swift +428 -0
  213. package/Sources/StoreKit/Transactions.swift +197 -0
  214. package/Sources/SwiftData/Macros.swift +58 -0
  215. package/Sources/SwiftData/ModelActor.swift +38 -0
  216. package/Sources/SwiftData/ModelContainer.swift +129 -0
  217. package/Sources/SwiftData/ModelContext.swift +451 -0
  218. package/Sources/SwiftData/PersistentModel.swift +238 -0
  219. package/Sources/SwiftData/Properties.swift +261 -0
  220. package/Sources/SwiftData/Query.swift +256 -0
  221. package/Sources/SwiftData/Schema.swift +192 -0
  222. package/Sources/SwiftData/Store.swift +146 -0
  223. package/Sources/SwiftData/StringPredicates.swift +125 -0
  224. package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
  225. package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
  226. package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
  227. package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
  228. package/Sources/SwiftDataMacros/Plugin.swift +18 -0
  229. package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
  230. package/Sources/SwiftUI/API/Accessibility.swift +55 -6
  231. package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
  232. package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
  233. package/Sources/SwiftUI/API/Alert.swift +1 -1
  234. package/Sources/SwiftUI/API/AlignmentGuides.swift +65 -0
  235. package/Sources/SwiftUI/API/Animation.swift +37 -5
  236. package/Sources/SwiftUI/API/App.swift +31 -1
  237. package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
  238. package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
  239. package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
  240. package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
  241. package/Sources/SwiftUI/API/Canvas.swift +337 -0
  242. package/Sources/SwiftUI/API/Color.swift +104 -28
  243. package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
  244. package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
  245. package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
  246. package/Sources/SwiftUI/API/Commands.swift +106 -0
  247. package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
  248. package/Sources/SwiftUI/API/ContentShape.swift +33 -0
  249. package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
  250. package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
  251. package/Sources/SwiftUI/API/Controls.swift +59 -27
  252. package/Sources/SwiftUI/API/CustomLayout.swift +49 -10
  253. package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
  254. package/Sources/SwiftUI/API/Decorations.swift +1 -1
  255. package/Sources/SwiftUI/API/EditMode.swift +25 -82
  256. package/Sources/SwiftUI/API/Effects.swift +105 -7
  257. package/Sources/SwiftUI/API/Entry.swift +8 -0
  258. package/Sources/SwiftUI/API/Environment.swift +93 -9
  259. package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
  260. package/Sources/SwiftUI/API/Focus.swift +11 -3
  261. package/Sources/SwiftUI/API/Gauge.swift +3 -2
  262. package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
  263. package/Sources/SwiftUI/API/GeometryReader.swift +13 -2
  264. package/Sources/SwiftUI/API/GestureState.swift +65 -0
  265. package/Sources/SwiftUI/API/Gestures.swift +1 -1
  266. package/Sources/SwiftUI/API/Glass.swift +127 -0
  267. package/Sources/SwiftUI/API/Grid.swift +1 -1
  268. package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
  269. package/Sources/SwiftUI/API/KeyPress.swift +54 -0
  270. package/Sources/SwiftUI/API/LabelStyle.swift +13 -6
  271. package/Sources/SwiftUI/API/Layout.swift +67 -12
  272. package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
  273. package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
  274. package/Sources/SwiftUI/API/Lists.swift +61 -6
  275. package/Sources/SwiftUI/API/Menu.swift +8 -1
  276. package/Sources/SwiftUI/API/Modifiers.swift +80 -10
  277. package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
  278. package/Sources/SwiftUI/API/Namespace.swift +44 -0
  279. package/Sources/SwiftUI/API/Navigation.swift +24 -9
  280. package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
  281. package/Sources/SwiftUI/API/ObservableObject.swift +16 -2
  282. package/Sources/SwiftUI/API/Path.swift +543 -0
  283. package/Sources/SwiftUI/API/Phase8Controls.swift +48 -31
  284. package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
  285. package/Sources/SwiftUI/API/Picker.swift +11 -2
  286. package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
  287. package/Sources/SwiftUI/API/Popover.swift +41 -0
  288. package/Sources/SwiftUI/API/Preferences.swift +262 -0
  289. package/Sources/SwiftUI/API/Presentation.swift +17 -4
  290. package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
  291. package/Sources/SwiftUI/API/Primitives.swift +164 -37
  292. package/Sources/SwiftUI/API/Publishers.swift +4 -4
  293. package/Sources/SwiftUI/API/Redaction.swift +75 -0
  294. package/Sources/SwiftUI/API/RowActions.swift +3 -2
  295. package/Sources/SwiftUI/API/Scenes.swift +131 -0
  296. package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
  297. package/Sources/SwiftUI/API/ScrollTargets.swift +3 -3
  298. package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
  299. package/Sources/SwiftUI/API/SectionSupplements.swift +96 -0
  300. package/Sources/SwiftUI/API/Shape.swift +214 -0
  301. package/Sources/SwiftUI/API/ShapeStyle.swift +105 -7
  302. package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
  303. package/Sources/SwiftUI/API/Sharing.swift +193 -0
  304. package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
  305. package/Sources/SwiftUI/API/State.swift +18 -1
  306. package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
  307. package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
  308. package/Sources/SwiftUI/API/TabContent.swift +841 -0
  309. package/Sources/SwiftUI/API/Table.swift +382 -0
  310. package/Sources/SwiftUI/API/Tabs.swift +148 -4
  311. package/Sources/SwiftUI/API/Tasks.swift +2 -2
  312. package/Sources/SwiftUI/API/Text.swift +386 -0
  313. package/Sources/SwiftUI/API/TextDates.swift +61 -0
  314. package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
  315. package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
  316. package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
  317. package/Sources/SwiftUI/API/Toolbar.swift +52 -16
  318. package/Sources/SwiftUI/API/Transfer.swift +145 -0
  319. package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
  320. package/Sources/SwiftUI/API/Video.swift +64 -0
  321. package/Sources/SwiftUI/API/View.swift +10 -2
  322. package/Sources/SwiftUI/API/ViewModifier.swift +4 -1
  323. package/Sources/SwiftUI/API/VisualEffect.swift +74 -1
  324. package/Sources/SwiftUI/API/Windows.swift +25 -0
  325. package/Sources/SwiftUI/Charts/Axis.swift +7 -1
  326. package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
  327. package/Sources/SwiftUI/Charts/Chart.swift +17 -3
  328. package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
  329. package/Sources/SwiftUI/Localization/Localization.swift +498 -0
  330. package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
  331. package/Sources/SwiftUI/Runtime/Executor.swift +2 -0
  332. package/Sources/SwiftUI/Runtime/Exports.swift +37 -1
  333. package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
  334. package/Sources/SwiftUI/Runtime/JSON.swift +76 -4
  335. package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
  336. package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
  337. package/Sources/SwiftUI/Runtime/Ops.swift +58 -12
  338. package/Sources/SwiftUI/Runtime/Reconciler.swift +10 -1
  339. package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
  340. package/Sources/SwiftUI/Runtime/Runtime.swift +977 -198
  341. package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
  342. package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
  343. package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
  344. package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
  345. package/Sources/Symbols/Symbols.swift +25 -0
  346. package/Sources/Translation/Translation.swift +423 -0
  347. package/Sources/UIKit/Activity.swift +213 -0
  348. package/Sources/UIKit/Alerts.swift +69 -0
  349. package/Sources/UIKit/AppDelegate.swift +222 -0
  350. package/Sources/UIKit/Appearance.swift +84 -0
  351. package/Sources/UIKit/ColorConversions.swift +70 -0
  352. package/Sources/UIKit/Controls.swift +225 -0
  353. package/Sources/UIKit/Device.swift +200 -0
  354. package/Sources/UIKit/Feedback.swift +65 -0
  355. package/Sources/UIKit/Font.swift +307 -0
  356. package/Sources/UIKit/Graphics.swift +204 -0
  357. package/Sources/UIKit/HostingController.swift +185 -0
  358. package/Sources/UIKit/Identity.swift +24 -0
  359. package/Sources/UIKit/Introspectable.swift +510 -0
  360. package/Sources/UIKit/Pasteboard.swift +363 -0
  361. package/Sources/UIKit/PhotoAlbum.swift +81 -0
  362. package/Sources/UIKit/RemoteNotifications.swift +15 -0
  363. package/Sources/UIKit/Representable.swift +288 -0
  364. package/Sources/UIKit/SafeArea.swift +12 -0
  365. package/Sources/UIKit/SceneDelegates.swift +132 -0
  366. package/Sources/UIKit/Scenes.swift +40 -0
  367. package/Sources/UIKit/ScrollView.swift +157 -0
  368. package/Sources/UIKit/ShortcutItems.swift +67 -0
  369. package/Sources/UIKit/SymbolConfiguration.swift +124 -0
  370. package/Sources/UIKit/TargetAction.swift +123 -0
  371. package/Sources/UIKit/TextPaste.swift +161 -0
  372. package/Sources/UIKit/TextView.swift +538 -0
  373. package/Sources/UIKit/UIKit.swift +292 -0
  374. package/Sources/UIKit/UIView.swift +855 -0
  375. package/Sources/UIKit/ViewTranslation.swift +311 -0
  376. package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
  377. package/Sources/UserNotifications/Content.swift +370 -0
  378. package/Sources/UserNotifications/NotificationCenter.swift +309 -0
  379. package/Sources/WeatherKit/WeatherKit.swift +228 -0
  380. package/Sources/WebKit/WebKit.swift +245 -0
  381. package/Sources/os/os.swift +376 -0
  382. package/Sources/zlib/zlib.swift +6 -0
  383. package/index.d.ts +1 -1
  384. package/index.mjs +2 -2
  385. package/manifest.d.mts +2 -0
  386. package/manifest.mjs +39 -0
  387. package/package.json +5 -3
  388. package/sync-sources.mjs +21 -7
  389. package/Sources/FoundationLite/Common.swift +0 -3
  390. package/Sources/FoundationLite/FoundationLite.swift +0 -171
  391. package/Sources/FoundationLite/Interaction.swift +0 -146
  392. package/Sources/FoundationLite/Timer.swift +0 -48
  393. package/Sources/_FoundationCommon/_FoundationCommon.swift +0 -10
@@ -0,0 +1,241 @@
1
+ //
2
+ // Publishers.CompactMap.swift
3
+ //
4
+ //
5
+ // Created by Sergej Jaskiewicz on 11.07.2019.
6
+ //
7
+
8
+ extension Publisher {
9
+
10
+ /// Calls a closure with each received element and publishes any returned optional
11
+ /// that has a value.
12
+ ///
13
+ /// OpenCombine’s `compactMap(_:)` operator performs a function similar to that of
14
+ /// `compactMap(_:)` in the Swift standard library: the `compactMap(_:)` operator in
15
+ /// OpenCombine removes `nil` elements in a publisher’s stream and republishes
16
+ /// non-`nil` elements to the downstream subscriber.
17
+ ///
18
+ /// The example below uses a range of numbers as the source for a collection based
19
+ /// publisher. The `compactMap(_:)` operator consumes each element from the `numbers`
20
+ /// publisher attempting to access the dictionary using the element as the key.
21
+ /// If the example’s dictionary returns a `nil`, due to a non-existent key,
22
+ /// `compactMap(_:)` filters out the `nil` (missing) elements.
23
+ ///
24
+ /// let numbers = (0...5)
25
+ /// let romanNumeralDict: [Int : String] =
26
+ /// [1: "I", 2: "II", 3: "III", 5: "V"]
27
+ ///
28
+ /// cancellable = numbers.publisher
29
+ /// .compactMap { romanNumeralDict[$0] }
30
+ /// .sink { print("\($0)", terminator: " ") }
31
+ ///
32
+ /// // Prints: "I II III V"
33
+ ///
34
+ /// - Parameter transform: A closure that receives a value and returns an optional
35
+ /// value.
36
+ /// - Returns: Any non-`nil` optional results of the calling the supplied closure.
37
+ public func compactMap<ElementOfResult>(
38
+ _ transform: @escaping (Output) -> ElementOfResult?
39
+ ) -> Publishers.CompactMap<Self, ElementOfResult> {
40
+ return .init(upstream: self, transform: transform)
41
+ }
42
+
43
+ /// Calls an error-throwing closure with each received element and publishes any
44
+ /// returned optional that has a value.
45
+ ///
46
+ /// Use `tryCompactMap(_:)` to remove `nil` elements from a publisher’s stream based
47
+ /// on an error-throwing closure you provide. If the closure throws an error,
48
+ /// the publisher cancels the upstream publisher and sends the thrown error to
49
+ /// the downstream subscriber as a `Publisher.Failure`.
50
+ ///
51
+ /// The following example uses an array of numbers as the source for
52
+ /// a collection-based publisher. A `tryCompactMap(_:)` operator consumes each integer
53
+ /// from the publisher and uses a dictionary to transform the numbers from its Arabic
54
+ /// to Roman numerals, as an optional `String`.
55
+ ///
56
+ /// If the closure called by `tryCompactMap(_:)` fails to look up a Roman numeral,
57
+ /// it returns the optional String `(unknown)`.
58
+ ///
59
+ /// If the closure called by `tryCompactMap(_:)` determines the input is `0`, it
60
+ /// throws an error. The `tryCompactMap(_:)` operator catches this error and stops
61
+ /// publishing, sending a `Subscribers.Completion.failure(_:)` that wraps the error.
62
+ ///
63
+ /// struct ParseError: Error {}
64
+ /// func romanNumeral(from: Int) throws -> String? {
65
+ /// let romanNumeralDict: [Int : String] =
66
+ /// [1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"]
67
+ /// guard from != 0 else { throw ParseError() }
68
+ /// return romanNumeralDict[from]
69
+ /// }
70
+ /// let numbers = [6, 5, 4, 3, 2, 1, 0]
71
+ /// cancellable = numbers.publisher
72
+ /// .tryCompactMap { try romanNumeral(from: $0) }
73
+ /// .sink(
74
+ /// receiveCompletion: { print ("\($0)") },
75
+ /// receiveValue: { print ("\($0)", terminator: " ") }
76
+ /// )
77
+ ///
78
+ /// // Prints: "(Unknown) V IV III II I failure(ParseError())"
79
+ ///
80
+ /// - Parameter transform: An error-throwing closure that receives a value and returns
81
+ /// an optional value.
82
+ /// - Returns: Any non-`nil` optional results of calling the supplied closure.
83
+ public func tryCompactMap<ElementOfResult>(
84
+ _ transform: @escaping (Output) throws -> ElementOfResult?
85
+ ) -> Publishers.TryCompactMap<Self, ElementOfResult> {
86
+ return .init(upstream: self, transform: transform)
87
+ }
88
+ }
89
+
90
+ extension Publishers.CompactMap {
91
+
92
+ public func compactMap<ElementOfResult>(
93
+ _ transform: @escaping (Output) -> ElementOfResult?
94
+ ) -> Publishers.CompactMap<Upstream, ElementOfResult> {
95
+ return .init(upstream: upstream,
96
+ transform: { self.transform($0).flatMap(transform) })
97
+ }
98
+
99
+ public func map<ElementOfResult>(
100
+ _ transform: @escaping (Output) -> ElementOfResult
101
+ ) -> Publishers.CompactMap<Upstream, ElementOfResult> {
102
+ return .init(upstream: upstream,
103
+ transform: { self.transform($0).map(transform) })
104
+ }
105
+ }
106
+
107
+ extension Publishers.TryCompactMap {
108
+
109
+ public func compactMap<ElementOfResult>(
110
+ _ transform: @escaping (Output) throws -> ElementOfResult?
111
+ ) -> Publishers.TryCompactMap<Upstream, ElementOfResult> {
112
+ return .init(upstream: upstream,
113
+ transform: { try self.transform($0).flatMap(transform) })
114
+ }
115
+ }
116
+
117
+ extension Publishers {
118
+
119
+ /// A publisher that republishes all non-`nil` results of calling a closure
120
+ /// with each received element.
121
+ public struct CompactMap<Upstream: Publisher, Output>: Publisher {
122
+
123
+ public typealias Failure = Upstream.Failure
124
+
125
+ /// The publisher from which this publisher receives elements.
126
+ public let upstream: Upstream
127
+
128
+ /// A closure that receives values from the upstream publisher
129
+ /// and returns optional values.
130
+ public let transform: (Upstream.Output) -> Output?
131
+
132
+ public init(upstream: Upstream,
133
+ transform: @escaping (Upstream.Output) -> Output?) {
134
+ self.upstream = upstream
135
+ self.transform = transform
136
+ }
137
+
138
+ public func receive<Downstream: Subscriber>(subscriber: Downstream)
139
+ where Downstream.Input == Output, Downstream.Failure == Failure
140
+ {
141
+ upstream.subscribe(Inner(downstream: subscriber, filter: transform))
142
+ }
143
+ }
144
+
145
+ /// A publisher that republishes all non-`nil` results of calling an error-throwing
146
+ /// closure with each received element.
147
+ public struct TryCompactMap<Upstream: Publisher, Output>: Publisher {
148
+
149
+ public typealias Failure = Error
150
+
151
+ /// The publisher from which this publisher receives elements.
152
+ public let upstream: Upstream
153
+
154
+ /// An error-throwing closure that receives values from the upstream publisher
155
+ /// and returns optional values.
156
+ ///
157
+ /// If this closure throws an error, the publisher fails.
158
+ public let transform: (Upstream.Output) throws -> Output?
159
+
160
+ public init(upstream: Upstream,
161
+ transform: @escaping (Upstream.Output) throws -> Output?) {
162
+ self.upstream = upstream
163
+ self.transform = transform
164
+ }
165
+
166
+ public func receive<Downstream: Subscriber>(subscriber: Downstream)
167
+ where Downstream.Input == Output, Downstream.Failure == Failure
168
+ {
169
+ upstream.subscribe(Inner(downstream: subscriber, filter: transform))
170
+ }
171
+ }
172
+ }
173
+
174
+ extension Publishers.CompactMap {
175
+ private struct Inner<Downstream: Subscriber>
176
+ : Subscriber,
177
+ CustomStringConvertible,
178
+ CustomReflectable,
179
+ CustomPlaygroundDisplayConvertible
180
+ where Upstream.Failure == Downstream.Failure
181
+ {
182
+ typealias Input = Upstream.Output
183
+ typealias Failure = Upstream.Failure
184
+
185
+ private let downstream: Downstream
186
+ private let filter: (Input) -> Downstream.Input?
187
+
188
+ let combineIdentifier = CombineIdentifier()
189
+
190
+ init(downstream: Downstream, filter: @escaping (Input) -> Downstream.Input?) {
191
+ self.downstream = downstream
192
+ self.filter = filter
193
+ }
194
+
195
+ func receive(subscription: Subscription) {
196
+ downstream.receive(subscription: subscription)
197
+ }
198
+
199
+ func receive(_ input: Input) -> Subscribers.Demand {
200
+ if let output = filter(input) {
201
+ return downstream.receive(output)
202
+ }
203
+ return .max(1)
204
+ }
205
+
206
+ func receive(completion: Subscribers.Completion<Failure>) {
207
+ downstream.receive(completion: completion)
208
+ }
209
+
210
+ var description: String { return "CompactMap" }
211
+
212
+ var customMirror: Mirror {
213
+ return Mirror(self, children: EmptyCollection())
214
+ }
215
+
216
+ var playgroundDescription: Any { return description }
217
+ }
218
+ }
219
+
220
+ extension Publishers.TryCompactMap {
221
+ private final class Inner<Downstream: Subscriber>
222
+ : FilterProducer<Downstream,
223
+ Upstream.Output,
224
+ Output,
225
+ Upstream.Failure,
226
+ (Upstream.Output) throws -> Output?>
227
+ where Downstream.Failure == Error, Downstream.Input == Output
228
+ {
229
+ override func receive(
230
+ newValue: Upstream.Output
231
+ ) -> PartialCompletion<Output?, Error> {
232
+ do {
233
+ return try .continue(filter(newValue))
234
+ } catch {
235
+ return .failure(error)
236
+ }
237
+ }
238
+
239
+ override var description: String { return "TryCompactMap" }
240
+ }
241
+ }
@@ -0,0 +1,371 @@
1
+ //
2
+ // Publishers.Comparison.swift
3
+ // OpenCombine
4
+ //
5
+ // Created by Ilija Puaca on 22/7/19.
6
+ //
7
+
8
+ extension Publisher where Output: Comparable {
9
+
10
+ /// Publishes the minimum value received from the upstream publisher, after it
11
+ /// finishes.
12
+ ///
13
+ /// Use `min()` to find the minimum value in a stream of elements from
14
+ /// an upstream publisher.
15
+ ///
16
+ /// In the example below, the `min()` operator emits a value when the publisher
17
+ /// finishes, that value is the minimum of the values received from upstream, which
18
+ /// is `-1`.
19
+ ///
20
+ /// let numbers = [-1, 0, 10, 5]
21
+ /// numbers.publisher
22
+ /// .min()
23
+ /// .sink { print("\($0)") }
24
+ ///
25
+ /// // Prints: "-1"
26
+ ///
27
+ /// After this publisher receives a request for more than 0 items, it requests
28
+ /// unlimited items from its upstream publisher.
29
+ ///
30
+ /// - Returns: A publisher that publishes the minimum value received from the upstream
31
+ /// publisher, after the upstream publisher finishes.
32
+ public func min() -> Publishers.Comparison<Self> {
33
+ return max(by: >)
34
+ }
35
+
36
+ /// Publishes the maximum value received from the upstream publisher, after it
37
+ /// finishes.
38
+ ///
39
+ /// Use `max()` to determine the maximum value in the stream of elements from
40
+ /// an upstream publisher.
41
+ ///
42
+ /// In the example below, the `max()` operator emits a value when the publisher
43
+ /// finishes, that value is the maximum of the values received from upstream, which
44
+ /// is `10`.
45
+ ///
46
+ /// let numbers = [0, 10, 5]
47
+ /// cancellable = numbers.publisher
48
+ /// .max()
49
+ /// .sink { print("\($0)") }
50
+ ///
51
+ /// // Prints: "10"
52
+ ///
53
+ /// After this publisher receives a request for more than 0 items, it requests
54
+ /// unlimited items from its upstream publisher.
55
+ ///
56
+ /// - Returns: A publisher that publishes the maximum value received from the upstream
57
+ /// publisher, after the upstream publisher finishes.
58
+ public func max() -> Publishers.Comparison<Self> {
59
+ return max(by: <)
60
+ }
61
+ }
62
+
63
+ extension Publisher {
64
+
65
+ /// Publishes the minimum value received from the upstream publisher, after it
66
+ /// finishes.
67
+ ///
68
+ /// Use `min(by:)` to determine the minimum value in the stream of elements from
69
+ /// an upstream publisher using a comparison operation you specify.
70
+ ///
71
+ /// This operator is useful when the value received from the upstream publisher isn’t
72
+ /// `Comparable`.
73
+ ///
74
+ /// In the example below an array publishes enumeration elements representing playing
75
+ /// card ranks. The `min(by:)` operator compares the current and next elements using
76
+ /// the `rawValue` property of each enumeration value in the user supplied closure and
77
+ /// prints the minimum value found after publishing all of the elements.
78
+ ///
79
+ /// enum Rank: Int {
80
+ /// case ace = 1, two, three, four, five, six, seven, eight, nine,
81
+ /// ten, jack, queen, king
82
+ /// }
83
+ ///
84
+ /// let cards: [Rank] = [.five, .queen, .ace, .eight, .king]
85
+ /// cancellable = cards.publisher
86
+ /// .min {
87
+ /// return $0.rawValue < $1.rawValue
88
+ /// }
89
+ /// .sink { print("\($0)") }
90
+ ///
91
+ /// // Prints: "ace"
92
+ ///
93
+ /// After this publisher receives a request for more than 0 items, it requests
94
+ /// unlimited items from its upstream publisher.
95
+ ///
96
+ /// - Parameter areInIncreasingOrder: A closure that receives two elements and returns
97
+ /// `true` if they’re in increasing order.
98
+ /// - Returns: A publisher that publishes the minimum value received from the upstream
99
+ /// publisher, after the upstream publisher finishes.
100
+ public func min(
101
+ by areInIncreasingOrder: @escaping (Output, Output) -> Bool
102
+ ) -> Publishers.Comparison<Self> {
103
+ return max(by: { areInIncreasingOrder($1, $0) })
104
+ }
105
+
106
+ /// Publishes the minimum value received from the upstream publisher, using
107
+ /// the provided error-throwing closure to order the items.
108
+ ///
109
+ /// Use `tryMin(by:)` to determine the minimum value of elements received from
110
+ /// the upstream publisher using an error-throwing closure you specify.
111
+ ///
112
+ /// In the example below, an array publishes elements. The `tryMin(by:)` operator
113
+ /// executes the error-throwing closure that throws when the `first` element is an odd
114
+ /// number, terminating the publisher.
115
+ ///
116
+ /// struct IllegalValueError: Error {}
117
+ ///
118
+ /// let numbers: [Int] = [0, 10, 6, 13, 22, 22]
119
+ /// numbers.publisher
120
+ /// .tryMin { first, second -> Bool in
121
+ /// if (first % 2 != 0) {
122
+ /// throw IllegalValueError()
123
+ /// }
124
+ /// return first < second
125
+ /// }
126
+ /// .sink(
127
+ /// receiveCompletion: { print ("completion: \($0)") },
128
+ /// receiveValue: { print ("value: \($0)") }
129
+ /// )
130
+ ///
131
+ /// // Prints: "completion: failure(IllegalValueError())"
132
+ ///
133
+ /// After this publisher receives a request for more than 0 items, it requests
134
+ /// unlimited items from its upstream publisher.
135
+ ///
136
+ /// - Parameter areInIncreasingOrder: A throwing closure that receives two elements
137
+ /// and returns `true` if they’re in increasing order. If this closure throws,
138
+ /// the publisher terminates with a `Subscribers.Completion.failure(_:)`.
139
+ /// - Returns: A publisher that publishes the minimum value received from the upstream
140
+ /// publisher, after the upstream publisher finishes.
141
+ public func tryMin(
142
+ by areInIncreasingOrder: @escaping (Output, Output) throws -> Bool
143
+ ) -> Publishers.TryComparison<Self> {
144
+ return tryMax(by: { try areInIncreasingOrder($1, $0) })
145
+ }
146
+
147
+ /// Publishes the maximum value received from the upstream publisher, using
148
+ /// the provided ordering closure.
149
+ ///
150
+ /// Use `max(by:)` to determine the maximum value of elements received from
151
+ /// the upstream publisher based on an ordering closure you specify.
152
+ ///
153
+ /// In the example below, an array publishes enumeration elements representing playing
154
+ /// card ranks. The `max(by:)` operator compares the current and next elements using
155
+ /// the `rawValue` property of each enumeration value in the user supplied closure and
156
+ /// prints the maximum value found after publishing all of the elements.
157
+ ///
158
+ /// enum Rank: Int {
159
+ /// case ace = 1, two, three, four, five, six, seven, eight, nine,
160
+ /// ten, jack, queen, king
161
+ /// }
162
+ ///
163
+ /// let cards: [Rank] = [.five, .queen, .ace, .eight, .jack]
164
+ /// cancellable = cards.publisher
165
+ /// .max {
166
+ /// return $0.rawValue > $1.rawValue
167
+ /// }
168
+ /// .sink { print("\($0)") }
169
+ ///
170
+ /// // Prints: "queen"
171
+ ///
172
+ /// After this publisher receives a request for more than 0 items, it requests
173
+ /// unlimited items from its upstream publisher.
174
+ ///
175
+ /// - Parameter areInIncreasingOrder: A closure that receives two elements and returns
176
+ /// `true` if they’re in increasing order.
177
+ /// - Returns: A publisher that publishes the maximum value received from the upstream
178
+ /// publisher, after the upstream publisher finishes.
179
+ public func max(
180
+ by areInIncreasingOrder: @escaping (Output, Output) -> Bool
181
+ ) -> Publishers.Comparison<Self> {
182
+ return .init(upstream: self, areInIncreasingOrder: areInIncreasingOrder)
183
+ }
184
+
185
+ /// Publishes the maximum value received from the upstream publisher, using
186
+ /// the provided error-throwing closure to order the items.
187
+ ///
188
+ /// Use `tryMax(by:)` to determine the maximum value of elements received from
189
+ /// the upstream publisher using an error-throwing closure you specify.
190
+ ///
191
+ /// In the example below, an array publishes elements. The `tryMax(by:)` operator
192
+ /// executes the error-throwing closure that throws when the `first` element is
193
+ /// an odd number, terminating the publisher.
194
+ ///
195
+ /// struct IllegalValueError: Error {}
196
+ ///
197
+ /// let numbers: [Int] = [0, 10, 6, 13, 22, 22]
198
+ /// cancellable = numbers.publisher
199
+ /// .tryMax { first, second -> Bool in
200
+ /// if (first % 2 != 0) {
201
+ /// throw IllegalValueError()
202
+ /// }
203
+ /// return first > second
204
+ /// }
205
+ /// .sink(
206
+ /// receiveCompletion: { print ("completion: \($0)") },
207
+ /// receiveValue: { print ("value: \($0)") }
208
+ /// )
209
+ ///
210
+ /// // Prints: completion: failure(IllegalValueError())
211
+ ///
212
+ /// After this publisher receives a request for more than 0 items, it requests
213
+ /// unlimited items from its upstream publisher.
214
+ ///
215
+ /// - Parameter areInIncreasingOrder: A throwing closure that receives two elements
216
+ /// and returns `true` if they’re in increasing order. If this closure throws,
217
+ /// the publisher terminates with a ``Subscribers/Completion/failure(_:)``.
218
+ ///
219
+ /// - Returns: A publisher that publishes the maximum value received from the upstream
220
+ /// publisher, after the upstream publisher finishes.
221
+ public func tryMax(
222
+ by areInIncreasingOrder: @escaping (Output, Output) throws -> Bool
223
+ ) -> Publishers.TryComparison<Self> {
224
+ return .init(upstream: self, areInIncreasingOrder: areInIncreasingOrder)
225
+ }
226
+ }
227
+
228
+ extension Publishers {
229
+
230
+ /// A publisher that republishes items from another publisher only if each new item is
231
+ /// in increasing order from the previously-published item.
232
+ public struct Comparison<Upstream: Publisher>: Publisher {
233
+
234
+ public typealias Output = Upstream.Output
235
+
236
+ public typealias Failure = Upstream.Failure
237
+
238
+ /// The publisher that this publisher receives elements from.
239
+ public let upstream: Upstream
240
+
241
+ /// A closure that receives two elements and returns `true` if they are in
242
+ /// increasing order.
243
+ public let areInIncreasingOrder: (Upstream.Output, Upstream.Output) -> Bool
244
+
245
+ public init(
246
+ upstream: Upstream,
247
+ areInIncreasingOrder: @escaping (Upstream.Output, Upstream.Output) -> Bool
248
+ ) {
249
+ self.upstream = upstream
250
+ self.areInIncreasingOrder = areInIncreasingOrder
251
+ }
252
+
253
+ public func receive<Downstream: Subscriber>(subscriber: Downstream)
254
+ where Upstream.Failure == Downstream.Failure,
255
+ Upstream.Output == Downstream.Input
256
+ {
257
+ let inner = Inner(downstream: subscriber,
258
+ areInIncreasingOrder: areInIncreasingOrder)
259
+ upstream.subscribe(inner)
260
+ }
261
+ }
262
+
263
+ /// A publisher that republishes items from another publisher only if each new item is
264
+ /// in increasing order from the previously-published item, and fails if the ordering
265
+ /// logic throws an error.
266
+ public struct TryComparison<Upstream: Publisher>: Publisher {
267
+
268
+ public typealias Output = Upstream.Output
269
+
270
+ public typealias Failure = Error
271
+
272
+ /// The publisher that this publisher receives elements from.
273
+ public let upstream: Upstream
274
+
275
+ /// A closure that receives two elements and returns `true` if they are in
276
+ /// increasing order.
277
+ public let areInIncreasingOrder: (Upstream.Output, Upstream.Output) throws -> Bool
278
+
279
+ public init(
280
+ upstream: Upstream,
281
+ areInIncreasingOrder:
282
+ @escaping (Upstream.Output, Upstream.Output) throws -> Bool
283
+ ) {
284
+ self.upstream = upstream
285
+ self.areInIncreasingOrder = areInIncreasingOrder
286
+ }
287
+
288
+ public func receive<Downstream: Subscriber>(subscriber: Downstream)
289
+ where Upstream.Output == Downstream.Input, Downstream.Failure == Error
290
+ {
291
+ let inner = Inner(downstream: subscriber,
292
+ areInIncreasingOrder: areInIncreasingOrder)
293
+ upstream.subscribe(inner)
294
+ }
295
+ }
296
+ }
297
+
298
+ extension Publishers.Comparison {
299
+ private final class Inner<Downstream: Subscriber>
300
+ : ReduceProducer<Downstream,
301
+ Upstream.Output,
302
+ Upstream.Output,
303
+ Upstream.Failure,
304
+ (Upstream.Output, Upstream.Output) -> Bool>
305
+ where Downstream.Input == Upstream.Output, Downstream.Failure == Upstream.Failure
306
+ {
307
+ fileprivate init(
308
+ downstream: Downstream,
309
+ areInIncreasingOrder: @escaping (Upstream.Output, Upstream.Output) -> Bool
310
+ ) {
311
+ super.init(downstream: downstream, initial: nil, reduce: areInIncreasingOrder)
312
+ }
313
+
314
+ override func receive(
315
+ newValue: Upstream.Output
316
+ ) -> PartialCompletion<Void, Downstream.Failure> {
317
+ if let result = self.result {
318
+ if reduce(result, newValue) {
319
+ self.result = newValue
320
+ }
321
+ } else {
322
+ self.result = newValue
323
+ }
324
+ return .continue
325
+ }
326
+
327
+ override var description: String {
328
+ return "Comparison"
329
+ }
330
+ }
331
+ }
332
+
333
+ extension Publishers.TryComparison {
334
+ private final class Inner<Downstream: Subscriber>
335
+ : ReduceProducer<Downstream,
336
+ Upstream.Output,
337
+ Upstream.Output,
338
+ Upstream.Failure,
339
+ (Upstream.Output, Upstream.Output) throws -> Bool>
340
+ where Downstream.Input == Upstream.Output, Downstream.Failure == Error
341
+ {
342
+ fileprivate init(
343
+ downstream: Downstream,
344
+ areInIncreasingOrder:
345
+ @escaping (Upstream.Output, Upstream.Output) throws -> Bool
346
+ ) {
347
+ super.init(downstream: downstream, initial: nil, reduce: areInIncreasingOrder)
348
+ }
349
+
350
+ override func receive(
351
+ newValue: Upstream.Output
352
+ ) -> PartialCompletion<Void, Downstream.Failure> {
353
+ do {
354
+ if let result = self.result {
355
+ if try reduce(result, newValue) {
356
+ self.result = newValue
357
+ }
358
+ } else {
359
+ self.result = newValue
360
+ }
361
+ return .continue
362
+ } catch {
363
+ return .failure(error)
364
+ }
365
+ }
366
+
367
+ override var description: String {
368
+ return "TryComparison"
369
+ }
370
+ }
371
+ }