Giter VIP home page Giter VIP logo

Comments (4)

yankodimitrov avatar yankodimitrov commented on June 16, 2024

Hi,

I see how this can be improved, however and(), or() and not() are too ambiguous names for functions/methods.

Maybe something like this:

combineLatest(mobileSignal, passwordSignal, smsCodeSignal)
    .map( reduceUsing(.And) )
    .bindTo( isEnabled(fetchCodeButton) )

Where reduceUsing is a curried function which accepts the kind of operation to use (.And or .Or) and returns a function which in its turn accepts a tuple with booleans that comes from applying map on the signal coming from combineLatest.

In Swift 2.0 using generic type extensions and protocol extensions we can implement something cleaner, so for now I will leave it as it is.

Thanks!

from signalkit.

yankodimitrov avatar yankodimitrov commented on June 16, 2024

Im happy to tell you that in SignalKit 1.0.0 we now have all and some signal operations for signals of tuple type (Bool, Bool) and (Bool, Bool, Bool)

Now you can write your example like this:

combineLatest(mobileSignal, passwordSignal, smsCodeSignal)
    .all { $0 == true }
    .bindTo(enabled: fetchCodeButton)

🎉

from signalkit.

lexrus avatar lexrus commented on June 16, 2024

Nice.
But what if I have 4 or more params to pass?

from signalkit.

yankodimitrov avatar yankodimitrov commented on June 16, 2024

You can combine them like this:

let signalA = ...
let signalB = ...
let signalC = ...
let signalD = ...

let signalAB = combineLatest(signalA, signalB).all { $0 == true }
let signalCD = combineLatest(signalC, signalD).all { $0 == true }

combineLatest(signalAB, signalCD)
    .all { $0 == true }
    .bindTo(enabled: button)

Or you can implement a free function combineLatest similarly to the one included in SignalKit that accepts 4 signals and then add a extension to SignalType protocol for the methods all and some for a signal of tuple type (Bool, Bool, Bool, Bool)

from signalkit.

Related Issues (18)

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.