cedric
03/07/2016, 2:53 PMcedric
03/07/2016, 2:54 PMreduce
although since the base is given, fold
might make more sense herekirillrakhman
03/07/2016, 2:54 PMcedric
03/07/2016, 2:54 PM= segments.reduce { a,b -> File(a,b).path }
(although this produces a String
, need to wrap it in a File
cedric
03/07/2016, 2:56 PMbase
so it’s buggy but you get the idea)kirillrakhman
03/07/2016, 2:57 PMcedric
03/07/2016, 2:57 PM= File(base, segments.joinToString(File.separator))
kirillrakhman
03/07/2016, 2:57 PMFile
will remove double separators, right?cedric
03/07/2016, 2:58 PMnormalize()
(or just ignore it since File
doesn’t mind AFAIR)kirillrakhman
03/07/2016, 2:59 PMjava.io.File#fixSlashes
says "Removes duplicate adjacent slashes and any trailing slash."kirillrakhman
03/07/2016, 2:59 PMmeh.
03/07/2016, 3:04 PMcompareBy
?kirillrakhman
03/07/2016, 3:05 PMmeh.
03/07/2016, 3:05 PMkirillrakhman
03/07/2016, 3:05 PMkotlin.comparisons
kirillrakhman
03/07/2016, 3:06 PMmeh.
03/07/2016, 3:07 PMkotlin
, all working now, thanksvoddan
03/08/2016, 12:13 PMmikehearn
03/08/2016, 12:33 PMmikehearn
03/08/2016, 12:33 PMkirillrakhman
03/08/2016, 12:35 PM==
should be enoughkirillrakhman
03/08/2016, 12:35 PMkirillrakhman
03/08/2016, 12:35 PMkirillrakhman
03/08/2016, 12:36 PMkirillrakhman
03/08/2016, 12:40 PMoperator fun <L : Any, R : Any> KClass<L>.compareTo(other: KClass<R>) = when {
this == other -> 0
this.java.isAssignableFrom(other.java) -> -1
other.java.isAssignableFrom(this.java) -> 1
else -> throw IllegalArgumentException("Classes doesn't have common hierarchy.")
}
works just as wellkirillrakhman
03/08/2016, 12:42 PMoperator fun KClass<*>.compareTo(other: KClass<*>) = when {
this == other -> 0
this.java.isAssignableFrom(other.java) -> -1
other.java.isAssignableFrom(this.java) -> 1
else -> throw IllegalArgumentException("Classes doesn't have common hierarchy.")
}
voddan
03/08/2016, 12:51 PMvoddan
03/08/2016, 12:52 PMvoddan
03/08/2016, 12:52 PMkirillrakhman
03/08/2016, 12:53 PMcompareTo
by throwing