Skip to content

Commit

Permalink
Address Ian's feedback - v2
Browse files Browse the repository at this point in the history
  • Loading branch information
spenes committed Jul 18, 2022
1 parent 83af36f commit 5ae6397
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ object S3 {
* parent path doesn't match with sub path.
*/
def diff(parent: Folder): Option[String] = {
val parentSplit = parent.split("/")
val subSplit = f.split("/")
val zipped = parentSplit.zip(subSplit)
if (zipped.length != parentSplit.length || zipped.length == subSplit.length) None
else {
val matched = zipped.foldLeft(true) {
case (false, _) => false
case (true, (s1, s2)) => s1 == s2
def go(parentParts: List[String], subParts: List[String]): Option[String] =
(parentParts, subParts) match {
case (_, Nil) =>
None
case (Nil, s) =>
Some(s.mkString("/"))
case (pHead :: _, sHead :: _) if pHead != sHead =>
None
case (pHead :: pTail, sHead :: sTail) if pHead == sHead =>
go(pTail, sTail)
}
if (matched) Some(subSplit.drop(zipped.length).mkString("/"))
else None
}

go(parent.split("/").toList, f.split("/").toList)
}
}

Expand Down

0 comments on commit 5ae6397

Please sign in to comment.