@swiftbrowser/swift 0.0.0-stage → 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.
- package/Package.swift +214 -0
- package/README.md +10 -2
- package/Sources/AVFoundation/AVFoundation.swift +131 -0
- package/Sources/AVFoundation/Asset.swift +487 -0
- package/Sources/AVFoundation/AudioSession.swift +144 -0
- package/Sources/AVFoundation/CMTime.swift +303 -0
- package/Sources/AVFoundation/Capture.swift +688 -0
- package/Sources/AVFoundation/Player.swift +749 -0
- package/Sources/AVFoundation/PlayerView.swift +117 -0
- package/Sources/AVKit/AVKit.swift +132 -0
- package/Sources/Accelerate/Accelerate.swift +122 -0
- package/Sources/AppIntents/AppIntents.swift +144 -0
- package/Sources/AppIntents/Parameters.swift +220 -0
- package/Sources/AppIntents/Shortcuts.swift +159 -0
- package/Sources/AudioToolbox/AudioToolbox.swift +55 -0
- package/Sources/AuthenticationServices/AuthenticationServices.swift +257 -0
- package/Sources/AuthenticationServices/Authorization.swift +251 -0
- package/Sources/Charts/Charts.swift +61 -0
- package/Sources/Combine/AnyCancellable.swift +65 -0
- package/Sources/Combine/AnyPublisher.swift +148 -0
- package/Sources/Combine/AnySubscriber.swift +230 -0
- package/Sources/Combine/Cancellable.swift +35 -0
- package/Sources/Combine/Codable.swift +29 -0
- package/Sources/Combine/CombineIdentifier.swift +45 -0
- package/Sources/Combine/Concurrency/ConcurrencyHelpers.swift +24 -0
- package/Sources/Combine/Concurrency/Future+Concurrency.swift +136 -0
- package/Sources/Combine/Concurrency/GENERATED-Publisher+Concurrency.swift +397 -0
- package/Sources/Combine/CurrentValueSubject.swift +252 -0
- package/Sources/Combine/CustomCombineIdentifierConvertible.swift +28 -0
- package/Sources/Combine/Future.swift +228 -0
- package/Sources/Combine/GENERATED-RootProtocols.swift +426 -0
- package/Sources/Combine/Helpers/ConduitBase.swift +40 -0
- package/Sources/Combine/Helpers/ConduitList.swift +59 -0
- package/Sources/Combine/Helpers/DebugHook.swift +177 -0
- package/Sources/Combine/Helpers/FilterProducer.swift +174 -0
- package/Sources/Combine/Helpers/Locking.swift +30 -0
- package/Sources/Combine/Helpers/PartialCompletion.swift +26 -0
- package/Sources/Combine/Helpers/ReduceProducer.swift +249 -0
- package/Sources/Combine/Helpers/SubjectSubscriber.swift +96 -0
- package/Sources/Combine/Helpers/SubscriberTap.swift +69 -0
- package/Sources/Combine/Helpers/SubscriptionStatus.swift +33 -0
- package/Sources/Combine/Helpers/SubscriptionTap.swift +33 -0
- package/Sources/Combine/Helpers/Utils.swift +30 -0
- package/Sources/Combine/Helpers/Violations.swift +33 -0
- package/Sources/Combine/ImmediateScheduler.swift +178 -0
- package/Sources/Combine/LICENSE +21 -0
- package/Sources/Combine/NotificationPublisher.swift +48 -0
- package/Sources/Combine/ObjectWillChange.swift +46 -0
- package/Sources/Combine/PassthroughSubject.swift +222 -0
- package/Sources/Combine/Publisher+Subscribe.swift +53 -0
- package/Sources/Combine/Publishers/Deferred.swift +48 -0
- package/Sources/Combine/Publishers/Empty.swift +54 -0
- package/Sources/Combine/Publishers/Fail.swift +42 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.Catch.swift +673 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.Encode.swift +388 -0
- package/Sources/Combine/Publishers/GENERATED-Publishers.MapKeyPath.swift +384 -0
- package/Sources/Combine/Publishers/Just.swift +313 -0
- package/Sources/Combine/Publishers/Optional.Publisher.swift +315 -0
- package/Sources/Combine/Publishers/Publishers.AllSatisfy.swift +217 -0
- package/Sources/Combine/Publishers/Publishers.AssertNoFailure.swift +158 -0
- package/Sources/Combine/Publishers/Publishers.Autoconnect.swift +193 -0
- package/Sources/Combine/Publishers/Publishers.Breakpoint.swift +231 -0
- package/Sources/Combine/Publishers/Publishers.Buffer.swift +356 -0
- package/Sources/Combine/Publishers/Publishers.Collect.swift +102 -0
- package/Sources/Combine/Publishers/Publishers.CollectByCount.swift +195 -0
- package/Sources/Combine/Publishers/Publishers.CompactMap.swift +241 -0
- package/Sources/Combine/Publishers/Publishers.Comparison.swift +371 -0
- package/Sources/Combine/Publishers/Publishers.Concatenate.swift +474 -0
- package/Sources/Combine/Publishers/Publishers.Contains.swift +293 -0
- package/Sources/Combine/Publishers/Publishers.Count.swift +87 -0
- package/Sources/Combine/Publishers/Publishers.Debounce.swift +332 -0
- package/Sources/Combine/Publishers/Publishers.Delay.swift +269 -0
- package/Sources/Combine/Publishers/Publishers.Drop.swift +155 -0
- package/Sources/Combine/Publishers/Publishers.DropUntilOutput.swift +283 -0
- package/Sources/Combine/Publishers/Publishers.DropWhile.swift +378 -0
- package/Sources/Combine/Publishers/Publishers.Filter.swift +248 -0
- package/Sources/Combine/Publishers/Publishers.First.swift +261 -0
- package/Sources/Combine/Publishers/Publishers.FlatMap.swift +533 -0
- package/Sources/Combine/Publishers/Publishers.HandleEvents.swift +260 -0
- package/Sources/Combine/Publishers/Publishers.IgnoreOutput.swift +109 -0
- package/Sources/Combine/Publishers/Publishers.Last.swift +252 -0
- package/Sources/Combine/Publishers/Publishers.MakeConnectable.swift +82 -0
- package/Sources/Combine/Publishers/Publishers.Map.swift +351 -0
- package/Sources/Combine/Publishers/Publishers.MapError.swift +140 -0
- package/Sources/Combine/Publishers/Publishers.MeasureInterval.swift +187 -0
- package/Sources/Combine/Publishers/Publishers.Multicast.swift +284 -0
- package/Sources/Combine/Publishers/Publishers.Output.swift +241 -0
- package/Sources/Combine/Publishers/Publishers.PrefixUntilOutput.swift +197 -0
- package/Sources/Combine/Publishers/Publishers.PrefixWhile.swift +176 -0
- package/Sources/Combine/Publishers/Publishers.Print.swift +206 -0
- package/Sources/Combine/Publishers/Publishers.ReceiveOn.swift +227 -0
- package/Sources/Combine/Publishers/Publishers.Reduce.swift +204 -0
- package/Sources/Combine/Publishers/Publishers.RemoveDuplicates.swift +264 -0
- package/Sources/Combine/Publishers/Publishers.ReplaceEmpty.swift +201 -0
- package/Sources/Combine/Publishers/Publishers.ReplaceError.swift +211 -0
- package/Sources/Combine/Publishers/Publishers.Retry.swift +274 -0
- package/Sources/Combine/Publishers/Publishers.Scan.swift +331 -0
- package/Sources/Combine/Publishers/Publishers.Sequence.swift +437 -0
- package/Sources/Combine/Publishers/Publishers.SetFailureType.swift +120 -0
- package/Sources/Combine/Publishers/Publishers.Share.swift +104 -0
- package/Sources/Combine/Publishers/Publishers.SubscribeOn.swift +197 -0
- package/Sources/Combine/Publishers/Publishers.SwitchToLatest.swift +444 -0
- package/Sources/Combine/Publishers/Publishers.Throttle.swift +359 -0
- package/Sources/Combine/Publishers/Publishers.Timeout.swift +301 -0
- package/Sources/Combine/Publishers/Publishers.Zip.swift +720 -0
- package/Sources/Combine/Publishers/Publishers.swift +13 -0
- package/Sources/Combine/Publishers/Record.swift +237 -0
- package/Sources/Combine/Publishers/Result.Publisher.swift +337 -0
- package/Sources/Combine/Result.swift +46 -0
- package/Sources/Combine/Scheduler.swift +89 -0
- package/Sources/Combine/Schedulers.swift +211 -0
- package/Sources/Combine/Subject+Void.swift +17 -0
- package/Sources/Combine/Subscriber+Void.swift +20 -0
- package/Sources/Combine/Subscribers/Subscribers.Assign.swift +175 -0
- package/Sources/Combine/Subscribers/Subscribers.Completion.swift +90 -0
- package/Sources/Combine/Subscribers/Subscribers.Demand.swift +476 -0
- package/Sources/Combine/Subscribers/Subscribers.Sink.swift +206 -0
- package/Sources/Combine/Subscribers/Subscribers.swift +9 -0
- package/Sources/Combine/Subscription.swift +22 -0
- package/Sources/Combine/Subscriptions.swift +42 -0
- package/Sources/Combine/SwiftUIObservation.swift +10 -0
- package/Sources/Combine/_Introspection.swift +107 -0
- package/Sources/CommonCrypto/CommonCrypto.swift +80 -0
- package/Sources/Compression/Compression.swift +365 -0
- package/Sources/Compression/Deflate.swift +407 -0
- package/Sources/Compression/Zlib.swift +179 -0
- package/Sources/CoreFoundationTypes/CoreFoundationTypes.swift +101 -0
- package/Sources/CoreGraphics/CoreGraphics.swift +411 -0
- package/Sources/CoreGraphics/ProjectionTransforms.swift +28 -0
- package/Sources/CoreHaptics/CoreHaptics.swift +399 -0
- package/Sources/CoreImage/CIColor.swift +41 -0
- package/Sources/CoreImage/CIContext.swift +31 -0
- package/Sources/CoreImage/CIDetector.swift +57 -0
- package/Sources/CoreImage/CIFilter.swift +243 -0
- package/Sources/CoreImage/CIFilterBuiltins.swift +136 -0
- package/Sources/CoreImage/CIImage.swift +162 -0
- package/Sources/CoreImage/QRCode.swift +393 -0
- package/Sources/CoreLocation/Coordinate.swift +30 -0
- package/Sources/CoreLocation/Location.swift +65 -0
- package/Sources/CoreML/Evaluation.swift +414 -0
- package/Sources/CoreML/FeatureValue.swift +266 -0
- package/Sources/CoreML/Model.swift +269 -0
- package/Sources/CoreML/MultiArray.swift +92 -0
- package/Sources/CoreML/Specification.swift +233 -0
- package/Sources/CoreText/CoreText.swift +64 -0
- package/Sources/CoreTransferable/CoreTransferable.swift +606 -0
- package/Sources/CryptoKit/ChaChaPoly.swift +258 -0
- package/Sources/CryptoKit/CryptoKit.swift +375 -0
- package/Sources/CryptoKit/Curve25519.swift +317 -0
- package/Sources/CryptoKit/P256.swift +321 -0
- package/Sources/FoundationBridge/AppStorage.swift +165 -0
- package/Sources/FoundationBridge/AssetResources.swift +90 -0
- package/Sources/FoundationBridge/AsyncBytes.swift +128 -0
- package/Sources/FoundationBridge/AsyncImage.swift +116 -0
- package/Sources/FoundationBridge/AttributedStrings.swift +16 -0
- package/Sources/FoundationBridge/Bundle.swift +119 -0
- package/Sources/FoundationBridge/CombineExports.swift +8 -0
- package/Sources/FoundationBridge/CoreFoundation.swift +77 -0
- package/Sources/FoundationBridge/Dispatch.swift +458 -0
- package/Sources/FoundationBridge/EnvironmentFoundation.swift +41 -0
- package/Sources/FoundationBridge/FileImporter.swift +128 -0
- package/Sources/FoundationBridge/FileSystem.swift +68 -0
- package/Sources/FoundationBridge/FoundationBridge.swift +29 -0
- package/Sources/FoundationBridge/HostResolution.swift +31 -0
- package/Sources/FoundationBridge/ItemProvider.swift +655 -0
- package/Sources/FoundationBridge/KeyValueObserving.swift +138 -0
- package/Sources/FoundationBridge/Links.swift +127 -0
- package/Sources/FoundationBridge/ListFormatter.swift +32 -0
- package/Sources/FoundationBridge/Locale.swift +86 -0
- package/Sources/FoundationBridge/Localization.swift +149 -0
- package/Sources/FoundationBridge/Locks.swift +50 -0
- package/Sources/FoundationBridge/Markdown.swift +527 -0
- package/Sources/FoundationBridge/MeasurementFormat.swift +95 -0
- package/Sources/FoundationBridge/NotificationCenter.swift +154 -0
- package/Sources/FoundationBridge/OpenURLHandlers.swift +60 -0
- package/Sources/FoundationBridge/Operation.swift +195 -0
- package/Sources/FoundationBridge/ProcessInfo.swift +32 -0
- package/Sources/FoundationBridge/RelativeDateTimeFormatter.swift +136 -0
- package/Sources/FoundationBridge/SceneStorage.swift +78 -0
- package/Sources/FoundationBridge/SecurityExports.swift +8 -0
- package/Sources/FoundationBridge/Selector.swift +226 -0
- package/Sources/FoundationBridge/StringComparators.swift +17 -0
- package/Sources/FoundationBridge/Table.swift +211 -0
- package/Sources/FoundationBridge/TextAttributes.swift +42 -0
- package/Sources/FoundationBridge/Timer.swift +53 -0
- package/Sources/FoundationBridge/UITextChecker.swift +30 -0
- package/Sources/FoundationBridge/URLSession.swift +718 -0
- package/Sources/FoundationBridge/UserDefaults.swift +183 -0
- package/Sources/FoundationBridge/WebAuthRedirects.swift +227 -0
- package/Sources/FoundationBridge/WebSocket.swift +187 -0
- package/Sources/FoundationModels/FoundationModels.swift +1098 -0
- package/Sources/ImageIO/GIF.swift +72 -0
- package/Sources/ImageIO/ImageIO.swift +248 -0
- package/Sources/ImageIO/ImageTypes.swift +28 -0
- package/Sources/LinkPresentation/LinkPresentation.swift +249 -0
- package/Sources/LocalAuthentication/LAContext.swift +86 -0
- package/Sources/MapKit/Geometry.swift +223 -0
- package/Sources/MapKit/Map.swift +638 -0
- package/Sources/MapKit/MapView.swift +229 -0
- package/Sources/MobileCoreServices/MobileCoreServices.swift +28 -0
- package/Sources/NaturalLanguage/LanguageIdentifier.swift +317 -0
- package/Sources/NaturalLanguage/NaturalLanguage.swift +135 -0
- package/Sources/OSLog/OSLog.swift +6 -0
- package/Sources/Photos/Photos.swift +572 -0
- package/Sources/PhotosUI/PhotosPicker.swift +248 -0
- package/Sources/PhotosUI/PhotosPickerItem.swift +261 -0
- package/Sources/QuickLook/QuickLook.swift +168 -0
- package/Sources/SafariServices/SafariServices.swift +106 -0
- package/Sources/Security/Security.swift +332 -0
- package/Sources/StoreKit/AppStore.swift +207 -0
- package/Sources/StoreKit/Products.swift +280 -0
- package/Sources/StoreKit/RequestReview.swift +28 -0
- package/Sources/StoreKit/StoreKit1.swift +486 -0
- package/Sources/StoreKit/StoreViews.swift +428 -0
- package/Sources/StoreKit/Transactions.swift +197 -0
- package/Sources/SwiftData/Macros.swift +58 -0
- package/Sources/SwiftData/ModelActor.swift +38 -0
- package/Sources/SwiftData/ModelContainer.swift +129 -0
- package/Sources/SwiftData/ModelContext.swift +451 -0
- package/Sources/SwiftData/PersistentModel.swift +238 -0
- package/Sources/SwiftData/Properties.swift +261 -0
- package/Sources/SwiftData/Query.swift +256 -0
- package/Sources/SwiftData/Schema.swift +192 -0
- package/Sources/SwiftData/Store.swift +146 -0
- package/Sources/SwiftData/StringPredicates.swift +125 -0
- package/Sources/SwiftDataMacros/EntryMacro.swift +82 -0
- package/Sources/SwiftDataMacros/GenerableMacro.swift +183 -0
- package/Sources/SwiftDataMacros/ModelActorMacro.swift +46 -0
- package/Sources/SwiftDataMacros/ModelMacro.swift +260 -0
- package/Sources/SwiftDataMacros/Plugin.swift +18 -0
- package/Sources/SwiftDataMacros/PredicateMacro.swift +1244 -0
- package/Sources/SwiftUI/API/Accessibility.swift +181 -0
- package/Sources/SwiftUI/API/AccessibilityExtras.swift +33 -0
- package/Sources/SwiftUI/API/AccessibilityFocus.swift +63 -0
- package/Sources/SwiftUI/API/Alert.swift +221 -0
- package/Sources/SwiftUI/API/AlignmentGuides.swift +65 -0
- package/Sources/SwiftUI/API/Animation.swift +285 -0
- package/Sources/SwiftUI/API/App.swift +87 -0
- package/Sources/SwiftUI/API/BindingCollections.swift +35 -0
- package/Sources/SwiftUI/API/BindingForEach.swift +27 -0
- package/Sources/SwiftUI/API/Bitmaps.swift +254 -0
- package/Sources/SwiftUI/API/ButtonStyles.swift +96 -0
- package/Sources/SwiftUI/API/Canvas.swift +337 -0
- package/Sources/SwiftUI/API/Color.swift +237 -0
- package/Sources/SwiftUI/API/ColorEffects.swift +52 -0
- package/Sources/SwiftUI/API/ColorPickerAndLabeledContent.swift +138 -0
- package/Sources/SwiftUI/API/ColorSpaces.swift +161 -0
- package/Sources/SwiftUI/API/Commands.swift +106 -0
- package/Sources/SwiftUI/API/ContainerBackground.swift +28 -0
- package/Sources/SwiftUI/API/ContentShape.swift +33 -0
- package/Sources/SwiftUI/API/ContentSizeCategory.swift +35 -0
- package/Sources/SwiftUI/API/ContentUnavailable.swift +101 -0
- package/Sources/SwiftUI/API/Controls.swift +300 -0
- package/Sources/SwiftUI/API/CustomLayout.swift +442 -0
- package/Sources/SwiftUI/API/CustomToolbarContent.swift +46 -0
- package/Sources/SwiftUI/API/Decorations.swift +92 -0
- package/Sources/SwiftUI/API/EditMode.swift +212 -0
- package/Sources/SwiftUI/API/Effects.swift +388 -0
- package/Sources/SwiftUI/API/Entry.swift +8 -0
- package/Sources/SwiftUI/API/Environment.swift +439 -0
- package/Sources/SwiftUI/API/EnvironmentSendable.swift +6 -0
- package/Sources/SwiftUI/API/Focus.swift +137 -0
- package/Sources/SwiftUI/API/Font.swift +131 -0
- package/Sources/SwiftUI/API/Gauge.swift +290 -0
- package/Sources/SwiftUI/API/Geometry.swift +89 -0
- package/Sources/SwiftUI/API/GeometryEffects.swift +232 -0
- package/Sources/SwiftUI/API/GeometryReader.swift +135 -0
- package/Sources/SwiftUI/API/GestureState.swift +65 -0
- package/Sources/SwiftUI/API/Gestures.swift +342 -0
- package/Sources/SwiftUI/API/Glass.swift +127 -0
- package/Sources/SwiftUI/API/Grid.swift +188 -0
- package/Sources/SwiftUI/API/GroupBoxAndControlGroup.swift +130 -0
- package/Sources/SwiftUI/API/KeyPress.swift +54 -0
- package/Sources/SwiftUI/API/LabelStyle.swift +124 -0
- package/Sources/SwiftUI/API/Layout.swift +220 -0
- package/Sources/SwiftUI/API/LazyStacks.swift +49 -0
- package/Sources/SwiftUI/API/LegacyAlert.swift +97 -0
- package/Sources/SwiftUI/API/Lists.swift +331 -0
- package/Sources/SwiftUI/API/Menu.swift +58 -0
- package/Sources/SwiftUI/API/Modifiers.swift +313 -0
- package/Sources/SwiftUI/API/MoreModifiers.swift +100 -0
- package/Sources/SwiftUI/API/Namespace.swift +44 -0
- package/Sources/SwiftUI/API/Navigation.swift +386 -0
- package/Sources/SwiftUI/API/NavigationDestinationBindings.swift +55 -0
- package/Sources/SwiftUI/API/ObservableObject.swift +293 -0
- package/Sources/SwiftUI/API/OnChange.swift +48 -0
- package/Sources/SwiftUI/API/Path.swift +543 -0
- package/Sources/SwiftUI/API/Phase8Controls.swift +411 -0
- package/Sources/SwiftUI/API/PhaseAnimator.swift +130 -0
- package/Sources/SwiftUI/API/Picker.swift +185 -0
- package/Sources/SwiftUI/API/PointerAndKeyboard.swift +77 -0
- package/Sources/SwiftUI/API/Popover.swift +41 -0
- package/Sources/SwiftUI/API/Preferences.swift +262 -0
- package/Sources/SwiftUI/API/Presentation.swift +122 -0
- package/Sources/SwiftUI/API/PresentationExtras.swift +60 -0
- package/Sources/SwiftUI/API/Primitives.swift +517 -0
- package/Sources/SwiftUI/API/Publishers.swift +107 -0
- package/Sources/SwiftUI/API/Redaction.swift +75 -0
- package/Sources/SwiftUI/API/RowActions.swift +84 -0
- package/Sources/SwiftUI/API/Scenes.swift +131 -0
- package/Sources/SwiftUI/API/ScrollModifiers.swift +132 -0
- package/Sources/SwiftUI/API/ScrollTargets.swift +104 -0
- package/Sources/SwiftUI/API/ScrollViewReader.swift +144 -0
- package/Sources/SwiftUI/API/SectionSupplements.swift +96 -0
- package/Sources/SwiftUI/API/Shape.swift +214 -0
- package/Sources/SwiftUI/API/ShapeStyle.swift +409 -0
- package/Sources/SwiftUI/API/ShapeTrim.swift +78 -0
- package/Sources/SwiftUI/API/Sharing.swift +193 -0
- package/Sources/SwiftUI/API/StackLayouts.swift +199 -0
- package/Sources/SwiftUI/API/State.swift +144 -0
- package/Sources/SwiftUI/API/StatusGaps.swift +121 -0
- package/Sources/SwiftUI/API/StrokeStyle.swift +30 -0
- package/Sources/SwiftUI/API/SymbolEffects.swift +203 -0
- package/Sources/SwiftUI/API/TabContent.swift +841 -0
- package/Sources/SwiftUI/API/Table.swift +382 -0
- package/Sources/SwiftUI/API/Tabs.swift +263 -0
- package/Sources/SwiftUI/API/Tasks.swift +35 -0
- package/Sources/SwiftUI/API/Text.swift +386 -0
- package/Sources/SwiftUI/API/TextDates.swift +61 -0
- package/Sources/SwiftUI/API/TextDecorations.swift +52 -0
- package/Sources/SwiftUI/API/TextFieldAxis.swift +103 -0
- package/Sources/SwiftUI/API/TextFieldCommit.swift +52 -0
- package/Sources/SwiftUI/API/Timeline.swift +212 -0
- package/Sources/SwiftUI/API/Toolbar.swift +251 -0
- package/Sources/SwiftUI/API/Transfer.swift +145 -0
- package/Sources/SwiftUI/API/UnevenRoundedRectangle.swift +66 -0
- package/Sources/SwiftUI/API/Video.swift +64 -0
- package/Sources/SwiftUI/API/View.swift +215 -0
- package/Sources/SwiftUI/API/ViewModifier.swift +43 -0
- package/Sources/SwiftUI/API/VisualEffect.swift +155 -0
- package/Sources/SwiftUI/API/Windows.swift +25 -0
- package/Sources/SwiftUI/Charts/Axis.swift +325 -0
- package/Sources/SwiftUI/Charts/AxisFormatsAndRanges.swift +68 -0
- package/Sources/SwiftUI/Charts/Chart.swift +660 -0
- package/Sources/SwiftUI/Charts/ChartContent.swift +376 -0
- package/Sources/SwiftUI/Charts/ChartProxy.swift +57 -0
- package/Sources/SwiftUI/Charts/Marks.swift +204 -0
- package/Sources/SwiftUI/Charts/Plottable.swift +99 -0
- package/Sources/SwiftUI/Charts/Scales.swift +326 -0
- package/Sources/SwiftUI/Localization/Localization.swift +498 -0
- package/Sources/SwiftUI/Localization/PluralRules.swift +127 -0
- package/Sources/SwiftUI/Runtime/Executor.swift +85 -0
- package/Sources/SwiftUI/Runtime/Exports.swift +101 -0
- package/Sources/SwiftUI/Runtime/ImageSource.swift +310 -0
- package/Sources/SwiftUI/Runtime/JSON.swift +143 -0
- package/Sources/SwiftUI/Runtime/JSONParser.swift +443 -0
- package/Sources/SwiftUI/Runtime/LazyRows.swift +99 -0
- package/Sources/SwiftUI/Runtime/Measurements.swift +140 -0
- package/Sources/SwiftUI/Runtime/Ops.swift +152 -0
- package/Sources/SwiftUI/Runtime/Reconciler.swift +219 -0
- package/Sources/SwiftUI/Runtime/Replay.swift +382 -0
- package/Sources/SwiftUI/Runtime/Runtime.swift +2146 -0
- package/Sources/SwiftUI/Runtime/Sameness.swift +152 -0
- package/Sources/SwiftUI/Runtime/ViewPath.swift +89 -0
- package/Sources/SwiftUI/Runtime/ViewTraits.swift +175 -0
- package/Sources/SwiftUI/Runtime/WebAuthHeadless.swift +49 -0
- package/Sources/Symbols/Symbols.swift +25 -0
- package/Sources/Translation/Translation.swift +423 -0
- package/Sources/UIKit/Activity.swift +213 -0
- package/Sources/UIKit/Alerts.swift +69 -0
- package/Sources/UIKit/AppDelegate.swift +222 -0
- package/Sources/UIKit/Appearance.swift +84 -0
- package/Sources/UIKit/ColorConversions.swift +70 -0
- package/Sources/UIKit/Controls.swift +225 -0
- package/Sources/UIKit/Device.swift +200 -0
- package/Sources/UIKit/Feedback.swift +65 -0
- package/Sources/UIKit/Font.swift +307 -0
- package/Sources/UIKit/Graphics.swift +204 -0
- package/Sources/UIKit/HostingController.swift +185 -0
- package/Sources/UIKit/Identity.swift +24 -0
- package/Sources/UIKit/Introspectable.swift +510 -0
- package/Sources/UIKit/Pasteboard.swift +363 -0
- package/Sources/UIKit/PhotoAlbum.swift +81 -0
- package/Sources/UIKit/RemoteNotifications.swift +15 -0
- package/Sources/UIKit/Representable.swift +288 -0
- package/Sources/UIKit/SafeArea.swift +12 -0
- package/Sources/UIKit/SceneDelegates.swift +132 -0
- package/Sources/UIKit/Scenes.swift +40 -0
- package/Sources/UIKit/ScrollView.swift +157 -0
- package/Sources/UIKit/ShortcutItems.swift +67 -0
- package/Sources/UIKit/SymbolConfiguration.swift +124 -0
- package/Sources/UIKit/TargetAction.swift +123 -0
- package/Sources/UIKit/TextPaste.swift +161 -0
- package/Sources/UIKit/TextView.swift +538 -0
- package/Sources/UIKit/UIKit.swift +292 -0
- package/Sources/UIKit/UIView.swift +855 -0
- package/Sources/UIKit/ViewTranslation.swift +311 -0
- package/Sources/UniformTypeIdentifiers/UTType.swift +196 -0
- package/Sources/UserNotifications/Content.swift +370 -0
- package/Sources/UserNotifications/NotificationCenter.swift +309 -0
- package/Sources/WeatherKit/WeatherKit.swift +228 -0
- package/Sources/WebKit/WebKit.swift +245 -0
- package/Sources/os/os.swift +376 -0
- package/Sources/zlib/zlib.swift +6 -0
- package/index.d.ts +2 -0
- package/index.mjs +16 -0
- package/manifest.d.mts +2 -0
- package/manifest.mjs +39 -0
- package/package.json +30 -4
- package/sync-sources.mjs +33 -0
|
@@ -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
|
+
}
|