Remove unnecessary FileDescriptor overrides#1129
Conversation
e9536ca to
c6e905c
Compare
c6e905c to
97c2124
Compare
jcazevedo
left a comment
There was a problem hiding this comment.
Thanks for this!
I think this change makes sense, but I would still keep open the opportunity for implementations to override specific methods (i.e. remove the finals), particularly with FileDescriptor not being sealed.
| * an iterator with the lines of this file. | ||
| */ | ||
| def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines() | ||
| final def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines() |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines() | |
| def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines() |
| * the new file descriptor with the updated path | ||
| */ | ||
| def /(name: String): Self = child(name) | ||
| final def /(name: String): Self = child(name) |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def /(name: String): Self = child(name) | |
| def /(name: String): Self = child(name) |
| * the new file descriptor with the updated path | ||
| */ | ||
| def children(names: String*): Self = | ||
| final def children(names: String*): Self = |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def children(names: String*): Self = | |
| def children(names: String*): Self = |
| * the new file descriptor with the updated path | ||
| */ | ||
| def cd(pathString: String): Self = { | ||
| final def cd(pathString: String): Self = { |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def cd(pathString: String): Self = { | |
| def cd(pathString: String): Self = { |
| * a new file descriptor pointing to a sibling of the current file descriptor | ||
| */ | ||
| def sibling(name: String): Self = sibling(_ => name) | ||
| final def sibling(name: String): Self = sibling(_ => name) |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def sibling(name: String): Self = sibling(_ => name) | |
| def sibling(name: String): Self = sibling(_ => name) |
There was a problem hiding this comment.
Please see 1549f5e.
I don't think this commit is removing the final keyword. Intended?
There was a problem hiding this comment.
Meant to comment on the inner sibling. I'll argue for keeping the final for the adapter methods next.
| * a new file descriptor pointing to a sibling of the current file descriptor | ||
| */ | ||
| def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self] | ||
| final def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self] |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self] | |
| def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self] |
| */ | ||
| def cd(pathString: String): Self = { | ||
| final def cd(pathString: String): Self = { | ||
| pathString.split("/").toList.foldLeft(this.asInstanceOf[Self]) { |
There was a problem hiding this comment.
All the implementations of this were trimming the individual splits. I can't recall why. Maybe we were just being overcautious for malformed inputs. That being said, it might not be a bad idea to keep the trimming in the overarching implementation for the time being.
| protected def duplicate(elements: List[String]): Self | ||
|
|
||
| def parent(n: Int = 1): Self = | ||
| final def parent(n: Int = 1): Self = |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def parent(n: Int = 1): Self = | |
| def parent(n: Int = 1): Self = |
| this.duplicate(elements = elements.dropRight(n)) | ||
|
|
||
| def child(name: String): Self = | ||
| final def child(name: String): Self = |
There was a problem hiding this comment.
I think it's still reasonable to give the option of implementations to redefine this, no?
| final def child(name: String): Self = | |
| def child(name: String): Self = |
3086784 to
19f3ab3
Compare
|
I agree that, in some cases, it might make sense to keep the possibility for implementations to override as needed for performance. However, in the cases of |
Co-authored-by: João Costa <jdpc557@gmail.com>
Fair enough. |
These operations are safe to perform at the base. There is no need to repeat them in implementations – they were sometimes slightly more efficient (e.g. not allocating intermediate wrappers while descending through child directories) but I don't think that is significant enough to maintain more code.
Does this change relate to existing issues or pull requests?
Opportunistic change after #1128.
Does this change require an update to the documentation?
No.
How has this been tested?
I am relying on the soundness of the
parentandchildimplementations.