Hullaballoonatic
06/20/2019, 6:46 PMclass Foo from Foo::class in any way?Shawn
06/20/2019, 6:47 PMShawn
06/20/2019, 6:47 PMShawn
06/20/2019, 6:47 PMHullaballoonatic
06/20/2019, 6:48 PMobject Metre : Unit("m", Length::class)Hullaballoonatic
06/20/2019, 6:48 PMMetre it will construct a quantity of LengthShawn
06/20/2019, 6:52 PMQuantity enum w/ LENGTH, MASS, TIME etcShawn
06/20/2019, 6:52 PMHullaballoonatic
06/20/2019, 6:53 PMHullaballoonatic
06/20/2019, 6:55 PMShawn
06/20/2019, 6:56 PMShawn
06/20/2019, 6:57 PMHullaballoonatic
06/20/2019, 6:57 PMHullaballoonatic
06/20/2019, 6:57 PMShawn
06/20/2019, 6:58 PMHullaballoonatic
06/20/2019, 6:59 PMShawn
06/20/2019, 6:59 PMnew to instantiate stuffShawn
06/20/2019, 6:59 PMShawn
06/20/2019, 6:59 PMHullaballoonatic
06/20/2019, 7:00 PMnew if we also had deleteDominaezzz
06/20/2019, 7:03 PMobject Metre : Unit("m", ::Length) ?Hullaballoonatic
06/20/2019, 7:03 PMDominaezzz
06/20/2019, 7:05 PMabstract class Unit(name: String, ctor: (Int) -> Value). I'm not sure what your constraints are or what your classes look like.Hullaballoonatic
06/20/2019, 7:13 PMDominaezzz
06/20/2019, 7:15 PMHullaballoonatic
06/20/2019, 7:41 PMabstract class Unit(name: String? = null, override val symbol: String, val quantities: List<KFunction1<Double, Quantity<*>>>) : Named,
Symbolic {
constructor(symbol: String, vararg quantities: KFunction1<Double, Quantity<*>>) : this(null, symbol, quantities.toList())
override val name: String = name ?: javaClass.simpleName.insertSpaces()
open val Double.toSIValue get() = this
inline operator fun <Q: Quantity<Q>, reified K: KFunction1<Double, Quantity<Q>>> invoke(value: Double): Quantity<Q> {
val constructor: K = quantities.first { it::returnType is K } as K
return constructor(value.toSIValue)
}
}
But we're gonna find out!Dominaezzz
06/20/2019, 7:47 PMHullaballoonatic
06/20/2019, 7:47 PMDominaezzz
06/20/2019, 7:49 PMabstract class Unit(
override name: String = javaClass.simpleName.insertSpaces(),
override val symbol: String,
val quantities: Map<KClass<out Quantity>, KFunction1<Double, Quantity<*>>>
) : Named, Symbolic {
constructor(symbol: String, vararg quantities: Pair<KClass<out Quantity>, KFunction1<Double, Quantity<*>>>) : this(symbol = symbol, quantities.toMap())
open val Double.toSIValue get() = this
inline operator fun <Q: Quantity<Q>, reified K: KFunction1<Double, Quantity<Q>>> invoke(value: Double): Quantity<Q> {
val constructor: K = quantities[Q::class] as K
return constructor(value.toSIValue)
}
}Dominaezzz
06/20/2019, 7:49 PMHullaballoonatic
06/20/2019, 7:51 PMKFunction1<Double, Quantity<*>> and a KClass<Quantity<*>>Hullaballoonatic
06/20/2019, 7:51 PMHullaballoonatic
06/20/2019, 7:52 PMDominaezzz
06/20/2019, 7:54 PMHullaballoonatic
06/20/2019, 7:57 PMDominaezzz
06/20/2019, 8:01 PMUnit("m", quant(::Length), quant(::Width)), with inline fun <reified Q: Quantity<Q>, reified K: KFunction1<Double, Quantity<Q>>> quant(k: K): Pair<KClass<Q>, K> = Q::class to k.Dominaezzz
06/20/2019, 8:02 PMHullaballoonatic
06/20/2019, 8:03 PMHullaballoonatic
06/20/2019, 8:03 PMHullaballoonatic
06/20/2019, 8:03 PMDominaezzz
06/20/2019, 8:03 PMDominaezzz
06/20/2019, 8:03 PMHullaballoonatic
06/20/2019, 8:03 PMHullaballoonatic
06/20/2019, 8:07 PMDominaezzz
06/20/2019, 8:11 PMHullaballoonatic
06/20/2019, 8:12 PMHullaballoonatic
06/20/2019, 8:12 PMDominaezzz
06/20/2019, 8:16 PMHullaballoonatic
06/20/2019, 8:38 PMHullaballoonatic
06/20/2019, 8:40 PMNewton, which can measure Force or WeightHullaballoonatic
06/20/2019, 8:40 PMHullaballoonatic
06/20/2019, 8:40 PMDominaezzz
06/20/2019, 8:41 PMDimension.Hullaballoonatic
06/20/2019, 8:41 PMHullaballoonatic
06/20/2019, 8:41 PMDominaezzz
06/20/2019, 8:41 PMHullaballoonatic
06/20/2019, 8:42 PMHullaballoonatic
06/20/2019, 8:42 PMDominaezzz
06/20/2019, 8:42 PMHullaballoonatic
06/20/2019, 8:43 PMHullaballoonatic
06/20/2019, 8:43 PMHullaballoonatic
06/20/2019, 8:43 PMHullaballoonatic
06/20/2019, 8:44 PMHullaballoonatic
06/20/2019, 8:44 PMDominaezzz
06/20/2019, 8:44 PMHullaballoonatic
06/20/2019, 8:44 PMHullaballoonatic
06/20/2019, 8:44 PMHullaballoonatic
06/20/2019, 8:45 PMDominaezzz
06/20/2019, 8:46 PMHullaballoonatic
06/20/2019, 8:46 PMDominaezzz
06/20/2019, 8:47 PMHullaballoonatic
06/20/2019, 8:47 PMHullaballoonatic
06/20/2019, 8:48 PM5.metre / 10.sec and get back a quantity in VelocityHullaballoonatic
06/20/2019, 8:48 PMDimension is going to make that process really efficientHullaballoonatic
06/20/2019, 8:49 PMForce or Weight as I mentioned aboveHullaballoonatic
06/20/2019, 8:50 PMHullaballoonatic
06/20/2019, 8:50 PMHullaballoonatic
06/20/2019, 8:51 PMDominaezzz
06/20/2019, 8:54 PMlouis993546
06/20/2019, 10:32 PMHullaballoonatic
06/20/2019, 10:36 PMval distance = 1.kilo.metre
val speed = 3.kilo.metre / 1.hour // converts to Velocity
println(speed == 40.kph) // true
println(distance == 1.km) // true
println("duration: ${distance / speed}") // 20 minuteslouis993546
06/20/2019, 11:46 PMHullaballoonatic
06/20/2019, 11:46 PMHullaballoonatic
06/20/2019, 11:47 PMbbaldino
06/21/2019, 4:06 PMLength derive from Unit, and then Metre derive from that? so Metre doesn't need to dynamically provide a sub-type to unit, it's there in the class hierarchy?Hullaballoonatic
06/21/2019, 4:09 PMbbaldino
06/21/2019, 4:10 PM