raulraja
11/06/2017, 10:24 AMraulraja
11/09/2017, 12:40 AMraulraja
11/09/2017, 12:41 AMJorge Castillo
11/11/2017, 12:38 PMpakoito
11/16/2017, 10:31 AMraulraja
11/21/2017, 1:38 AMraulraja
12/08/2017, 3:07 AMraulraja
12/08/2017, 3:09 AMdh44t
12/22/2017, 9:47 AMdh44t
12/22/2017, 9:47 AMraulraja
01/15/2018, 3:19 PMhelpermethod
01/17/2018, 10:05 AMhelpermethod
01/17/2018, 10:05 AMhelpermethod
01/17/2018, 10:06 AMhelpermethod
01/17/2018, 10:06 AMhelpermethod
01/17/2018, 10:07 AMhelpermethod
01/17/2018, 10:09 AMprivate val reflections = Reflections()
fun getRouterName() =
reflections
.getTypesAnnotatedWith(MCMain::class.java, false)
.first()
.simpleName
fun getElements() =
reflections
.getTypesAnnotatedWith(MCElement::class.java)
fun getChildElements(type: Class<*>) =
getAllMethods(type, withAnnotation(MCChildElement::class.java))
fun getSubTypes(type: Class<*>) =
reflections
.getSubTypesOf(type)
.filter { it.isAnnotationPresent(MCElement::class.java) }
raulraja
01/17/2018, 10:29 AMfirst()
is an unsafe api and it may blow up, you should probably use firstOrNull
which is safe:
data class RouterName(val name: String)
fun getRouterName(): Option<RouterName> =
Option.fromNullable(
reflections
.getTypesAnnotatedWith(MCMain::class.java, false)
.firstOrNull()
).map { RouterName(it.simpleName) }
I would add explicit return types since they seem to be public functions. Normally you can call it functional if:
- Given an input it always produces the same output (functions are pure)
- Does not use global mutable state
- Does not modify the outer state
- Side Effects are encapsulated in functions or data types that allow deferring their executionhelpermethod
01/17/2018, 12:22 PMhelpermethod
01/18/2018, 10:24 AMlupajz
01/18/2018, 11:02 AM.fold({ throw some exception }, { .. continue with right })
could work ?simon.vergauwen
01/18/2018, 11:13 AMflatMap
or monad bindings then it short circuits on failure.simon.vergauwen
01/18/2018, 11:15 AMfold
or handle in any other way you desire like showing user a message.raulraja
01/18/2018, 11:56 AMraulraja
01/18/2018, 11:56 AMOption
, Try
, Either
and MonadError
and comparing them to throwing exceptions.helpermethod
01/18/2018, 1:02 PMsimon.vergauwen
01/18/2018, 1:54 PM