Skip to content

Makes objects function more swifty.#74

Closed
valeriyvan wants to merge 2 commits intoInstagram:masterfrom
valeriyvan:swift
Closed

Makes objects function more swifty.#74
valeriyvan wants to merge 2 commits intoInstagram:masterfrom
valeriyvan:swift

Conversation

@valeriyvan
Copy link
Copy Markdown
Contributor

Changes in this pull request

Makes objects function more swifty.

Pull request checklist

  • [x ] All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • [ x] I have reviewed the contributing guide

@rnystrom
Copy link
Copy Markdown
Contributor

@jessesquires had some comments on the last swifty PR we did after I merged it, gonna let him take a quick look at this before we import.

}
}
return items
guard selectedClass != nil else { return data.map { $0 as! IGListDiffable } }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this would be easier to read if we put the return on a newline and the final } on a newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, else clause of guard statement should be on separate line if it has something substantially longer of simple return.

}
return items
guard selectedClass != nil else { return data.map { $0 as! IGListDiffable } }
return data.filter { type(of: $0) == selectedClass! }.map { $0 as! IGListDiffable }
Copy link
Copy Markdown
Contributor

@jessesquires jessesquires Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, now i remember the issues I saw with this. scratch that first comment. 😄

the previous version combined the 2 conditions in a single if. Now this is broken up and harder to follow, not to mention we've written .map { $0 as! IGListDiffable } twice. 😊

why can't the initial filter contain both conditions? couldn't this be something like this?

return data.filter { 
        if let theClass = selectedClass { 
            return type(of: $0) == theClass 
        } 
        return false
        }.map { $0 as! IGListDiffable }

I think this is more readable + more concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, initial filter could have both conditions.
But it hides that if selectedClass is nil, function returns just it's input array with transformed elements.
Otherwise it filters input array and then transforms it's elements.
Version I am proposing keeps that clear.
Less condensed but more clear.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@valeriyvan updated the pull request - view changes

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thanks for importing. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants