Giter Site home page Giter Site logo

Generics in `map:` about reactiveobjc HOT 5 OPEN

reactivecocoa avatar reactivecocoa commented on April 27, 2024
Generics in `map:`

from reactiveobjc.

Comments (5)

Pitometsu avatar Pitometsu commented on April 27, 2024

Maybe, use some macros to avoid prefix notation?

from reactiveobjc.

Pitometsu avatar Pitometsu commented on April 27, 2024

So something like

[signal map:^OutputType(InputType obj) { ... }]

should be expanded by macro to something like

    [ ({ Mapper<InputType, OutputType> *mapper = Mapper.new; })
      map: signal
withBlock: ^OutputType(InputType obj) { ... } ]

// or even (Signal already have one generic, so Mapper may just inherit it):
//
// [ ({ Mapper<OutputType> *mapper = [Mapper mapperWithSignal:signal]; }) map:
//  ^OutputType(InputType obj) { ... } ]
//

Or use type casting instead of scopes: [ ((Mapper<InputType, OutputType> *)Mapper.new) map...

It will be even easier:

replace just

signal map:^OutputType

by

((Mapper<OutputType> *)Mapper mapperWithSignal:signal]).map:^OutputType

from reactiveobjc.

Pitometsu avatar Pitometsu commented on April 27, 2024

However, it may broke -map: autocompletion, but compiler will check return value to match proper generic.

from reactiveobjc.

mdiep avatar mdiep commented on April 27, 2024

I don't think it's worth the time to try to build something like this for Objective-C—especially since this concept can't be implemented cleanly. IMO you're better off spending that time trying to migrate your code to Swift.

from reactiveobjc.

Pitometsu avatar Pitometsu commented on April 27, 2024

I can't migrate to Swift until it have backward binary compatibility. Anyway, ObjC still here, and would be nice to have type safe map: for it too.

from reactiveobjc.

Related Issues (20)

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.