just solved the Birthday Kata with Arrow, if anyon...
# arrow
s
just solved the Birthday Kata with Arrow, if anyone has the time to take a look, any feedback is appreciated, thanks -> https://github.com/LordRaydenMK/BirthdayKata
❤️ 5
s
Hey Stojan, just checked it out. Looks awesome!
I think the
ServiceLogger
could be improved tho
logError(::logError) { “Error reading employees from repo” }
Looks here you’re calling
logError
on
IO
concretely and then passing a lambda there from
LoggingService
. It looks like it can be encoded in just a single method within
LoggingService
.
s
the outer
logError
is an extension function on
IO
Copy code
fun <A> IO<A>.logError(log: (Throwable, () -> String?) -> IO<Unit>, msg: () -> String? = { null }): IO<A> =
    handleErrorWith { log(it, msg).followedBy(IO.raiseError(it)) }
the
logError
method reference comes from
LoggingService
s
This could be an alternative encoding
Yes, I realise but it can be fused into a single method which could also be easily refactored to
F
later this way 😉
👍 1
s
thanks, will give it a try
s
This removes all impl details / complexity from the call site
s
I am too used to
Timber.d
without caring about IO and stuff 😂
s
Haha 😄 Well this is what I’d do for analytics rather than development debugging
But I personally prefer to keep
Timder.d
out of git since most people have their own preferences/styles of doing debugging/logging.
s
so you would not use IO for logging?
s
Well I don’t leave logging in code is what I am saying ;D
I remove it before I push
You use
Timber.d
for stuff like
Opened Settings Activity
etc, right?
Which is not relevant to business or users. If it gets messy (or buggy) it’s a headache for devs rather than anyone else
So that would completely depend on your policy for dev logging which I prefer to keep out of the code. So I should write a lint rule or something to not allow Timber 😄
s
got it, thanks 😉
Based on your suggestion I came up with
Copy code
interface LoggingService {

    fun logError(t: Throwable, msg: () -> String?): IO<Unit>

    fun <A> IO<A>.logError(msg: (Throwable) -> String?) =
        handleErrorWith { logError(it) { msg(it) }.followedBy(IO.raiseError(it)) }
}
I love this pattern, a simple operation and then deriving a more complex one based on it
j
is logging part of the kata spec?
i tend to minimize logging libraries right up to the point where im debugging asyncronous crypto transactions and too much magic exists for debugging. then i paper every possible relevant line with an assertion based logger that requires -ea to be not removed from the jvm
s
Nope, not a part of the spec, but I wanted to try it out 😁
Maybe removing it now makes sense, so it doesn't add noise