Giter Site home page Giter Site logo

rxoptional's Introduction

RxOptional

CircleCI Version License Platform

RxSwift extensions for Swift optionals and "Occupiable" types.

Usage

All operators are also available on Driver and Signal, unless otherwise noted.

Optional Operators

filterNil
Observable<String?>
    .of("One", nil, "Three")
    .filterNil()
    // Type is now Observable<String>
    .subscribe { print($0) }
next(One)
next(Three)
completed
replaceNilWith
Observable<String?>
    .of("One", nil, "Three")
    .replaceNilWith("Two")
    // Type is now Observable<String>
    .subscribe { print($0) }
next(One)
next(Two)
next(Three)
completed
errorOnNil

Unavailable on Driver, because Drivers cannot error out.

By default errors with RxOptionalError.foundNilWhileUnwrappingOptional.

Observable<String?>
    .of("One", nil, "Three")
    .errorOnNil()
    // Type is now Observable<String>
    .subscribe { print($0) }
next(One)
error(Found nil while trying to unwrap type <Optional<String>>)
catchOnNil
Observable<String?>
    .of("One", nil, "Three")
    .catchOnNil {
        return Observable<String>.just("A String from a new Observable")
    }
    // Type is now Observable<String>
    .subscribe { print($0) }
next(One)
next(A String from a new Observable)
next(Three)
completed
distinctUntilChanged
Observable<Int?>
    .of(5, 6, 6, nil, nil, 3)
    .distinctUntilChanged()
    .subscribe { print($0) }
next(Optional(5))
next(Optional(6))
next(nil)
next(Optional(3))
completed

Occupiable Operators

Occupiables are:

  • String
  • Array
  • Dictionary
  • Set

Currently in Swift protocols cannot be extended to conform to other protocols. For now the types listed above conform to Occupiable. You can also conform custom types to Occupiable.

filterEmpty
Observable<[String]>
    .of(["Single Element"], [], ["Two", "Elements"])
    .filterEmpty()
    .subscribe { print($0) }
next(["Single Element"])
next(["Two", "Elements"])
completed
errorOnEmpty

Unavailable on Driver, because Drivers cannot error out.

By default errors with RxOptionalError.emptyOccupiable.

Observable<[String]>
    .of(["Single Element"], [], ["Two", "Elements"])
    .errorOnEmpty()
    .subscribe { print($0) }
next(["Single Element"])
error(Empty occupiable of type <Array<String>>)
catchOnEmpty
Observable<[String]>
    .of(["Single Element"], [], ["Two", "Elements"])
    .catchOnEmpty {
        return Observable<[String]>.just(["Not Empty"])
    }
    .subscribe { print($0) }
next(["Single Element"])
next(["Not Empty"])
next(["Two", "Elements"])
completed

Running Examples.playground

  • Run pod install in Example directory
  • Select RxOptional Examples target
  • Build
  • Show Debug Area (cmd+shift+Y)
  • Click blue play button in Debug Area

Requirements

Installation

RxOptional is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxOptional'

Add this to Cartfile

github "RxSwiftCommunity/RxOptional" ~> 4.1.0
$ carthage update

To use RxOptional as a Swift Package Manager package just add the following in your Package.swift file.

import PackageDescription

let package = Package(
    name: "ProjectName",
    dependencies: [
        .Package(url: "https://github.com/RxSwiftCommunity/RxOptional")
    ]
)

Author

Thane Gill, [email protected]

License

RxOptional is available under the MIT license. See the LICENSE file for more info.

rxoptional's People

Contributors

ashfurrow avatar behzadardehei avatar clementleroy avatar cruisediary avatar dentelezhkin avatar dependabot[bot] avatar e-kazakov avatar fassko avatar freak4pc avatar gettoset avatar hartbit avatar iandundas avatar ikesyo avatar ivanbruel avatar ivanmisuno-albelli avatar jegnux avatar lutzifer avatar minuscorp avatar muukii avatar pinddfull avatar rafaelsachetto avatar rynecheow avatar scotteg avatar sendyhalim avatar siuying avatar thanegill avatar tonyarnold avatar vhbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxoptional's Issues

New release to fix Carthage issues with RxOptional release 3.4.0

We are able to continue using RxOptional locally by applying the fix to our local version of RxOptional, but any carthage update either locally or in our CI environment will cause compilation errors. Please make a point release to keep RxOptional building in Carthage properly.

codebuild: error: Unable to find a destination on carthage build

cartfile
github "RxSwiftCommunity/RxOptional"

Command
carthage build RxOptional --platform watchOS

Error Log
`codebuild: error: Unable to find a destination matching the provided destination specifier:
{ platform:watchOS Simulator, id:48D0931A-D041-4D51-9BEB-FA8D924CA1C0 }

Ineligible destinations for the "RxOptional watchOS" scheme:
	{ platform:watchOS, id:dvtdevice-DVTiOSDevicePlaceholder-watchos:placeholder, name:Generic watchOS Device }
	{ platform:watchOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-watchsimulator:placeholder, name:Generic watchOS Simulator Device }

A shell task (/usr/bin/xcrun xcodebuild -project /Users/henry.hong/workspace/scmp-mobile/scmp-ios/Carthage/Checkouts/RxOptional/RxOptional.xcodeproj -scheme RxOptional watchOS -configuration Release -sdk watchsimulator -destination platform=watchOS Simulator,id=48D0931A-D041-4D51-9BEB-FA8D924CA1C0 -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 70:
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
{ platform:watchOS Simulator, id:48D0931A-D041-4D51-9BEB-FA8D924CA1C0 }

Ineligible destinations for the "RxOptional watchOS" scheme:
	{ platform:watchOS, id:dvtdevice-DVTiOSDevicePlaceholder-watchos:placeholder, name:Generic watchOS Device }
	{ platform:watchOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-watchsimulator:placeholder, name:Generic watchOS Simulator Device }`

Cannot update to RxSwift 5.x when using Carthage

When including this extension via Carthage, an update checks out RxSwift 3.0.0 beta 1, and not RxSwift 5.0.0 as expected.

I'd hazard a guess that the version restriction in the Cartfile needs to be lifted from 4.3.1 to 5.0.0.

Carthage update failed (3.4.0)

This problem occurs in Xcode 9.3(9E145).

Console log:

$ carthage update --cache-builds --platform iOS

...

*** Invalid cache found for RxOptional, rebuilding with all downstream dependencies
*** Building scheme "RxOptional iOS" in RxOptional.xcodeproj
Build Failed
	Task failed with exit code 70:
	/usr/bin/xcrun xcodebuild -project /Users/kawoou/GitHub/PROJECT_NAME/Carthage/Checkouts/RxOptional/RxOptional.xcodeproj -scheme RxOptional\ iOS -configuration Release -derivedDataPath /Users/felix/Library/Caches/org.carthage.CarthageKit/DerivedData/9.3_9E145/RxOptional/3.4.0 -sdk iphonesimulator -destination platform=iOS\ Simulator,id=26B572BA-40F0-4CE6-BDD6-4C08E1A522F0 -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/kawoou/GitHub/PROJECT_NAME/Carthage/Checkouts/RxOptional)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/l3/ggj8jv5s69n9fp29726kl9j40000gn/T/carthage-xcodebuild.gu8p5L.log

/var/folders/l3/ggj8jv5s69n9fp29726kl9j40000gn/T/carthage-xcodebuild.gu8p5L.log:

...

** ARCHIVE SUCCEEDED **

/usr/bin/xcrun xcodebuild -project /Users/kawoou/GitHub/PROJECT_NAME/Carthage/Checkouts/RxOptional/RxOptional.xcodeproj -scheme RxOptional\ iOS -configuration Release -derivedDataPath /Users/kawoou/Library/Caches/org.carthage.CarthageKit/DerivedData/9.3_9E145/RxOptional/3.4.0 -sdk iphonesimulator -destination platform=iOS\ Simulator,id=26B572BA-40F0-4CE6-BDD6-4C08E1A522F0 -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/kawoou/GitHub/PROJECT_NAME/Carthage/Checkouts/RxOptional)User defaults from command line:
    IDEDerivedDataPathOverride = /Users/kawoou/Library/Caches/org.carthage.CarthageKit/DerivedData/9.3_9E145/RxOptional/3.4.0

Build settings from command line:
    CARTHAGE = YES
    CODE_SIGN_IDENTITY =
    CODE_SIGNING_REQUIRED = NO
    ONLY_ACTIVE_ARCH = NO
    SDKROOT = iphonesimulator11.3

Build settings from configuration file '/tmp/static.xcconfig.xDDGZ8':
    DEBUG_INFORMATION_FORMAT = dwarf
    LD = /Users/kawoou/GitHub/PROJECT_NAME/tools/ld.py

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
        { platform:iOS Simulator, id:26B572BA-40F0-4CE6-BDD6-4C08E1A522F0 }

    Available destinations for the "RxOptional iOS" scheme:
        { platform:iOS, id:5c2a6220b935cc96ead1c5b66fddc303ecc2f898, name:Dev25 }

    Ineligible destinations for the "RxOptional iOS" scheme:
        { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Generic iOS Device }
        { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Generic iOS Simulator Device }

3.3.0 breaking changes with Carthage

Hi,

The last version, 3.3.0, includes breaking changes with RxSwift 4.0 implementation resulting an error when we launch a "carthage update" if we use RxSwift 3.6 in the project.

To according to Semantic Versioning, the version should be 4.0.0 ?

"Linking against dylib not safe for..." when framework is installed through Carthage

Hello,

Xcode 10.2 gives me the following warning for my watchOS extension when RxOptional is added to the WatchApp Extension through Carthage:

ld: warning: linking against a dylib which is not safe for use in application extensions: ..../Carthage/Build/watchOS/RxOptional.framework/RxOptional

My Carthage.resolved reference points to this
github "RxSwiftCommunity/RxOptional" "1c37ab2d84823babc0d09ebe0b70ade3bee25829

Any ideas how to fix this ?

Regards,
Mihai

Carthage update broken after 4.1.0

When running carthage update the following error is received

A shell task (/usr/bin/env git fetch --prune --quiet https://github.com/RxSwiftCommunity/RxOptional.git refs/tags/:refs/tags/ +refs/heads/:refs/heads/ (launched in /Users/cameronmcgorian/Library/Caches/org.carthage.CarthageKit/dependencies/RxOptional)) failed with exit code 1

Seems like this occurred after the 4.1.0 release?

Switch to Circle CI

Travis builds are taking hours, we need to switch to Circle. Happy to do this unless someone else wants to.

Depreciate fatalErrorOn* Operators

They don't seem to be a good idea. They:

  • Promote bad design
  • For the majority of the cases falls back to some other operator.
  • Can't test.

Deprecating in 1.2 and removing in 2.0.

Any reason to not remove these operators @RxSwiftCommunity/contributors?

Can't access to any method and class of Rx Optional

Hi,
I would like to ask some question.
I have a problem in using RxOptional.

I installed RxOptional into my project.but I couldn't use any method and class.
When jumping to definition, there is no definition like the photo below.
スクリーンショット 2019-10-18 5 12 39

There seems to have a problem, but I don't know how to deal with it.

my Xcode version is 11.0. I installed it with Xcode built-in SPM. The library version 4.0.1.

Could someone help it?

Thanks,

filterNil rename to unwrapNil

Shouldn't we keep filter as a plucking of items in the stream without modifying the underlying generic type?
Since the act of retrieving a type from String? to String is usually deemed as unwrapping nullables, I suggest we keep.
At least filterAndUnwrap.

Thoughts?

Moving RxOptional to RxSwiftExt project

Hi @RxSwiftCommunity/contributors! I have a proposal to merge RxOptional into RxSwiftExt.
Both these project follow similar great target - make RxSwift users life easier with custom handy operators. I think it might be a good idea to have one repo with all custom operators, not two or more. It will also make maintaining, updates and resolving issues easier. And, of course, it will increase users number, cause some folks once found RxOptional and don’t know about RxSwiftExt or visa versa.

What do you think? Please, share your thoughts. In case you like this idea, I am ready to handle migration process.

P.S. Got approval on that from @thanegill. Interested in community thoughts.
P.P.S. We all have to stay united in the face of Apple Combine
cc @freak4pc

Update CI config

Discussed here and below, our CI is borked. It's linked to from the readme. It doesn't even appear to be configured. We should fix it.

Fix CI

Borked in #18 because of Swift updates, probably. Needs investigation.

Duplicate CI builds

Our current Travis setup has four schemes which kick of four distinct builds on Travis. However, carthage bootstrap is run on each build and it builds for all platforms, so we're doing the same work four times (I think someone please double check my logic here). Seems like we might be able to speed up CI by getting rid of building unnecessary schemes?

Error building from Carthage "xcodebuild: error: Unable to read project 'RxOptional-SPM.xcodeproj' from folder"

When building RxOptional 5.0.0 using Carthage with Xcode 12.3 I get this error

A shell task (/usr/bin/xcrun xcodebuild -project /Users/landon/dev/app/Carthage/Checkouts/RxOptional/RxOptional-SPM.xcodeproj CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -list) failed with exit code 74:
xcodebuild: error: Unable to read project 'RxOptional-SPM.xcodeproj' from folder '/Users/landon/dev/app/Carthage/Checkouts/RxOptional'.
Reason: Project /Users/landon/dev/app/Carthage/Checkouts/RxOptional/RxOptional-SPM.xcodeproj cannot be opened because it is missing its project.pbxproj file.

Swift 5 support

Any updates on Swift 5 support?

Can we have a binary compiled with Swift 5 please?

Thanks

3.1.0 does not install — missing tag

3.1.0 hasn't been tagged yet:

[!] Error installing RxOptional
[!] /usr/local/bin/git clone https://github.com/RxSwiftCommunity/RxOptional.git /var/folders/6_/lg037wnj3c141xr3zb1lfkn40000gp/T/d20161009-38154-11sz7ht --single-branch --depth 1 --branch 3.1.0

Cloning into '/var/folders/6_/lg037wnj3c141xr3zb1lfkn40000gp/T/d20161009-38154-11sz7ht'...
warning: Could not find remote branch 3.1.0 to clone.
fatal: Remote branch 3.1.0 not found in upstream origin

Handling of null values of respones?

I'm mapping this JSON object:

{
...
"completedDate": null,
...
}

struct TaskResult : Mappable{
.....
let completedDate : Int?
}
return MyProvider.rx.request(.request005())
.debug()
.mapOptional(to: [TaskResult].self, keyPath: "data")

I got a nil mapping result ,any idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.