Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Nil filter method on array #59

Closed
michaeleisel opened this issue Jan 8, 2015 · 3 comments
Closed

Nil filter method on array #59

michaeleisel opened this issue Jan 8, 2015 · 3 comments

Comments

@michaeleisel
Copy link
Contributor

Sometimes I want to, given an array of an optional type, return an array of the corresponding non-optional type, where all nil values have been filtered out. Here's my best attempt, but it doesn't compile: https://gist.github.com/michaeleisel/32f7e80ce2186f1edc95

Any ideas?

@nickmshelley
Copy link
Contributor

Why not just mapFilter with the identity function?

@pNre
Copy link
Owner

pNre commented Jan 9, 2015

You can't write an extension that only applies to an array of optionals.
As @nickmshelley suggests, you can do:

array.mapFilter(mapFunction: { $0 })

@michaeleisel
Copy link
Contributor Author

Yeah mapFilter was perfect, thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants