Skip to content

Commit

Permalink
Merge pull request #10 from hamtiko/master
Browse files Browse the repository at this point in the history
Adding support for Single and Maybe PrimitiveSequenceTypes
  • Loading branch information
Tigran Hambardzumyan authored May 14, 2020
2 parents 3c65a51 + 2f660bd commit 7c7c0fa
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 87 deletions.
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

24 changes: 12 additions & 12 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
PODS:
- RxCocoa (5.0.0):
- RxCocoa (5.1.1):
- RxRelay (~> 5)
- RxSwift (~> 5)
- RxRelay (5.0.0):
- RxSwift (~> 5)
- RxSwift (5.0.0)
- STDevRxExt (0.1.5):
- RxCocoa (~> 5)
- RxRelay (5.1.1):
- RxSwift (~> 5)
- RxSwift (5.1.1)
- STDevRxExt (0.2.0):
- RxCocoa (~> 5.1)
- RxSwift (~> 5.1)

DEPENDENCIES:
- STDevRxExt (from `../`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
trunk:
- RxCocoa
- RxRelay
- RxSwift
Expand All @@ -23,11 +23,11 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
RxCocoa: fcf32050ac00d801f34a7f71d5e8e7f23026dcd8
RxRelay: 4f7409406a51a55cd88483f21ed898c234d60f18
RxSwift: 8b0671caa829a763bbce7271095859121cbd895f
STDevRxExt: 1b62df5fe5ec25219a4bb081fdd57c77094911cb
RxCocoa: 32065309a38d29b5b0db858819b5bf9ef038b601
RxRelay: d77f7d771495f43c556cbc43eebd1bb54d01e8e9
RxSwift: 81470a2074fa8780320ea5fe4102807cb7118178
STDevRxExt: 2bd7d233a4990c8e227b6af52ac3cc51e7ecb333

PODFILE CHECKSUM: 83769abc0b7bdc83a928dcac34cf2b1154077760

COCOAPODS: 1.7.0
COCOAPODS: 1.9.1
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# STDevRxExt

[![CI Status](http://img.shields.io/travis/stdevteam/STDevRxExt.svg?style=flat)](https://travis-ci.org/stdevteam/STDevRxExt)
[![CI Status](http://img.shields.io/travis/STDevTM/STDevRxExt.svg?style=flat)](https://travis-ci.org/STDevTM/STDevRxExt)
[![Version](https://img.shields.io/cocoapods/v/STDevRxExt.svg?style=flat)](http://cocoapods.org/pods/STDevRxExt)
[![License](https://img.shields.io/cocoapods/l/STDevRxExt.svg?style=flat)](http://cocoapods.org/pods/STDevRxExt)
[![Platform](https://img.shields.io/cocoapods/p/STDevRxExt.svg?style=flat)](http://cocoapods.org/pods/STDevRxExt)
Expand All @@ -13,7 +13,7 @@ To run the [Example.playground](Example/Example.playground), clone the repo, and

* iOS 10.0+
* Swift 5.0+
* Xcode 10.2+
* Xcode 11+

## Installation

Expand Down Expand Up @@ -237,7 +237,7 @@ Tigran Hambardzumyan, tigran@stdevmail.com

## Support

Feel free to [open issuses](https://github.com/stdevteam/STDevRxExt/issues/new) with any suggestions, bug reports, feature requests, questions.
Feel free to [open issues](https://github.com/STDevTM/STDevRxExt/issues/new) with any suggestions, bug reports, feature requests, questions.

## Let us know!

Expand Down
12 changes: 5 additions & 7 deletions STDevRxExt.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'STDevRxExt'
s.version = '0.1.6'
s.version = '0.2.0'
s.summary = 'STDevRxExt contains some extension functions for RxSwift and RxCoca which makes our live easy.'
s.swift_version = '5.0'

Expand All @@ -12,17 +12,15 @@ STDevRxExt contains following 3 type of extensions for RxSwift and RxCocoa:
* more coming soon
DESC

s.homepage = 'https://github.com/stdevteam/STDevRxExt'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.homepage = 'https://github.com/STDevTM/STDevRxExt'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Tigran Hambardzumyan' => 'tigran@stdevmail.com' }
s.source = { :git => 'https://github.com/stdevteam/STDevRxExt.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.source = { :git => 'https://github.com/STDevTM/STDevRxExt.git', :tag => s.version.to_s }

s.ios.deployment_target = '10.0'

s.source_files = 'STDevRxExt/Classes/**/*'

s.dependency 'RxSwift', '~> 5'
s.dependency 'RxCocoa', '~> 5'
s.dependency 'RxSwift', '~> 5.1'
s.dependency 'RxCocoa', '~> 5.1'
end
25 changes: 20 additions & 5 deletions STDevRxExt/Classes/CastExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
// Created by Tigran Hambardzumyan on 3/28/18.
//

import Foundation
import RxSwift
import RxCocoa
import RxSwift

public enum RxCastError: Error {
case castFailed
}

public extension ObservableType {
// MARK: - Observable

public extension ObservableType {
func cast<T>(to type: T.Type) -> Observable<T?> {
return map { $0 as? T }
}
Expand All @@ -32,13 +32,28 @@ public extension ObservableType {
}
}
}

}

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy {
// MARK: - Driver

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy {
func cast<T>(to type: T.Type) -> Driver<T?> {
return map { $0 as? T }
}
}

// MARK: - Single

public extension PrimitiveSequenceType where Trait == SingleTrait {
func cast<T>(to type: T.Type) -> Single<T?> {
return map { $0 as? T }
}
}

// MARK: - Maybe

public extension PrimitiveSequenceType where Trait == MaybeTrait {
func cast<T>(to type: T.Type) -> Maybe<T?> {
return map { $0 as? T }
}
}
127 changes: 108 additions & 19 deletions STDevRxExt/Classes/FilterExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
// Created by Tigran Hambardzumyan on 3/28/18.
//

import Foundation
import RxSwift
import RxCocoa
import RxSwift

public extension ObservableType where Element == Bool {
// MARK: - Observable

public extension ObservableType where Element == Bool {
func allowTrue() -> Observable<Bool> {
return filter { $0 }
}

func allowFalse() -> Observable<Bool> {
return filter { !$0 }
}

}

public extension ObservableType where Element == Bool? {

func allowTrue() -> Observable<Bool> {
return map { $0 ?? false }
.allowTrue()
Expand All @@ -42,43 +40,37 @@ public extension ObservableType where Element == Bool? {
return map { $0 ?? false }
.allowFalse()
}

}

public extension ObservableType {

func filterIfNil(_ param: Optional<Any>) -> Observable<Element> {
func filterIfNil(_ param: Any?) -> Observable<Element> {
return filter { _ in param != nil }
}

func filterIfNotNil(_ param: Optional<Any>) -> Observable<Element> {
func filterIfNotNil(_ param: Any?) -> Observable<Element> {
return filter { _ in param == nil }
}

}

public extension ObservableType where Element == Optional<Any> {

public extension ObservableType where Element == Any? {
func allowNil() -> Observable<Element> {
return filter { $0 == nil }
}

}

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy, Element == Bool {
// MARK: - Driver

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy, Element == Bool {
func allowTrue() -> Driver<Bool> {
return filter { $0 }
}

func allowFalse() -> Driver<Bool> {
return filter { !$0 }
}

}

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy, Element == Bool? {

func allowTrue() -> Driver<Bool> {
return map { $0 ?? false }
.allowTrue()
Expand All @@ -98,17 +90,114 @@ public extension SharedSequenceConvertibleType where SharingStrategy == DriverSh
return map { $0 ?? false }
.allowFalse()
}

}

public extension SharedSequenceConvertibleType where SharingStrategy == DriverSharingStrategy {
func filterIfNil(_ param: Any?) -> Driver<Element> {
return filter { _ in param == nil }
}

func filterIfNotNil(_ param: Any?) -> Driver<Element> {
return filter { _ in param != nil }
}
}

// MARK: - Single

public extension PrimitiveSequenceType where Trait == SingleTrait, Element == Bool {
func allowTrue() -> Maybe<Bool> {
return filter { $0 }
}

func allowFalse() -> Maybe<Bool> {
return filter { !$0 }
}
}

public extension PrimitiveSequenceType where Trait == SingleTrait, Element == Bool? {
func allowTrue() -> Maybe<Bool> {
return map { $0 ?? false }
.allowTrue()
}

func allowTrueOrNil() -> Maybe<Bool> {
return map { $0 ?? true }
.allowTrue()
}

func allowFalse() -> Maybe<Bool> {
return map { $0 ?? true }
.allowFalse()
}

func allowFalseOrNil() -> Maybe<Bool> {
return map { $0 ?? false }
.allowFalse()
}
}

func filterIfNil(_ param: Optional<Any>) -> Driver<Element> {
public extension PrimitiveSequenceType where Trait == SingleTrait {
func filterIfNil(_ param: Any?) -> Maybe<Element> {
return filter { _ in param != nil }
}

func filterIfNotNil(_ param: Any?) -> Maybe<Element> {
return filter { _ in param == nil }
}
}

public extension PrimitiveSequenceType where Trait == SingleTrait, Element == Any? {
func allowNil() -> Maybe<Element> {
return filter { $0 == nil }
}
}

// MARK: - Maybe

public extension PrimitiveSequenceType where Trait == MaybeTrait, Element == Bool {
func allowTrue() -> Maybe<Bool> {
return filter { $0 }
}

func filterIfNotNil(_ param: Optional<Any>) -> Driver<Element> {
func allowFalse() -> Maybe<Bool> {
return filter { !$0 }
}
}

public extension PrimitiveSequenceType where Trait == MaybeTrait, Element == Bool? {
func allowTrue() -> Maybe<Bool> {
return map { $0 ?? false }
.allowTrue()
}

func allowTrueOrNil() -> Maybe<Bool> {
return map { $0 ?? true }
.allowTrue()
}

func allowFalse() -> Maybe<Bool> {
return map { $0 ?? true }
.allowFalse()
}

func allowFalseOrNil() -> Maybe<Bool> {
return map { $0 ?? false }
.allowFalse()
}
}

public extension PrimitiveSequenceType where Trait == MaybeTrait {
func filterIfNil(_ param: Any?) -> Maybe<Element> {
return filter { _ in param != nil }
}

func filterIfNotNil(_ param: Any?) -> Maybe<Element> {
return filter { _ in param == nil }
}
}

public extension PrimitiveSequenceType where Trait == MaybeTrait, Element == Any? {
func allowNil() -> Maybe<Element> {
return filter { $0 == nil }
}
}
Loading

0 comments on commit 7c7c0fa

Please sign in to comment.