jazzy icon indicating copy to clipboard operation
jazzy copied to clipboard

Separate operators from functions

Open kareman opened this issue 9 years ago • 18 comments

Even though Swift operators are technically functions I think it would be useful to at least optionally list operators under their own heading. Especially in this case where there is a function $ which now looks like an operator.

kareman avatar May 19 '15 19:05 kareman

Thanks for the feature request! I don't know if it's possible for us to do, but we'll keep this open to track it anyway.

jpsim avatar Nov 24 '15 01:11 jpsim

+1

nickplee avatar Feb 01 '16 21:02 nickplee

Would be great to have! One of my documentations “Other Functions” section currently looks like this:

<(_:_:)
<(_:_:)
<(_:_:)
<(_:_:)
<(_:_:)
==(_:_:)
==(_:_:)
==(_:_:)
==(_:_:)
==(_:_:)
==(_:_:)

p2 avatar Feb 09 '16 15:02 p2

Just curious, how do you all think this should be handled in the generated HTML?

I totally agree it's not very useful to have a bunch of ==(_:_:) functions.

Maybe an Operator Functions category that uses the declaration instead of the name? For Realm Swift, it would look like this:

==(lhs: ErrorType, rhs: ErrorType) -> Bool
==(lhs: ObjectSchema, rhs: ObjectSchema) -> Bool
==(lhs: Property, rhs: Property) -> Bool
==(lhs: Realm, rhs: Realm) -> Bool
==(lhs: Schema, rhs: Schema) -> Bool
==(lhs: SortDescriptor, rhs: SortDescriptor) -> Bool

Here's an entirely different idea of how it could be displayed:

ErrorType == ErrorType
ObjectSchema == ObjectSchema
Property == Property
Realm == Realm
Schema == Schema
SortDescriptor == SortDescriptor

Implementation aside, how would this ideally work for you?

jpsim avatar Jun 10 '16 00:06 jpsim

Another option would be to list each operator once, and on that operators page have each implementation

segiddins avatar Jun 10 '16 00:06 segiddins

ooh, I like that idea

jpsim avatar Jun 10 '16 00:06 jpsim

Yes I think I would prefer listing each operator once too. Less clutter in the menu.

kareman avatar Jun 10 '16 01:06 kareman

Thumbs up to all of this.

Sent from my iPhone

On Jun 9, 2016, at 9:06 PM, Kare Morstol [email protected] wrote:

Yes I think I would prefer listing each operator once too. Less clutter in the menu.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

nickplee avatar Jun 10 '16 01:06 nickplee

screenshot 2016-06-09 20 41 53

segiddins avatar Jun 10 '16 01:06 segiddins

This is also an option: screenshot 2016-06-09 20 50 12

segiddins avatar Jun 10 '16 01:06 segiddins

I'd not need the operators listed in the menu, just appear on the page of the type definition. So whenever I look at the type, I se that it conforms to Equatable and co.

p2 avatar Jun 10 '16 02:06 p2

@p2 the trouble with that is that operators (and functions in general) don't 'belong' to any type

segiddins avatar Jun 10 '16 02:06 segiddins

Sure, and probably only few add an empty extension Type: Equatable { } before the definition. Still, it's what I'd like to look my docs like. :)

p2 avatar Jun 10 '16 02:06 p2

FWIW, Xcode 8b5 now allows to move these into the type bodies, wohoo!

public struct Foo: Equatable {
    var value: String
    public static func ==(lhs: Foo, rhs: Foo) -> Bool {
        return lhs.value == rhs.value
    }
}

p2 avatar Aug 10 '16 13:08 p2

I believe this issue has been resolved as per @p2's last comment. Feel free to re-open if there's more to be done that I missed. Still getting familiar with the project. :)

karagraysen avatar Nov 23 '16 15:11 karagraysen

No, I think @p2's excitement was more for the language feature than what this ticket is tracking.

jpsim avatar Nov 26 '16 01:11 jpsim

I realized that afterwards. My apologies - sounds good though.

karagraysen avatar Nov 26 '16 01:11 karagraysen

FWIW, there is some overlap with #787 here regarding how to display operators. For non-symmetric operators like, say, <=(lhs: Int, rhs: Int/Double/...) the default <=(_:_:) is still not helpful. (As in, even if all operators are declared in their "mother" types as opposed to at the top level).

reitzig avatar Apr 26 '17 13:04 reitzig