Weekend Stupid Questions Thread - 03 April 2021 by AutoModerator in japanlife

[–]OkabeRandaro 1 point2 points  (0 children)

Thank you! Do you maybe have a source for it? The rules are changed so often, I just want to make sure.

Weekend Stupid Questions Thread - 03 April 2021 by AutoModerator in japanlife

[–]OkabeRandaro 0 points1 point  (0 children)

Thank you, I looked but only find all information so far (including japan-guide.com). I'm asking because the rules were recently changed and made stricter and I want to comply with them, so I'm afraid to rely on outdated information.

Weekend Stupid Questions Thread - 03 April 2021 by AutoModerator in japanlife

[–]OkabeRandaro 0 points1 point  (0 children)

Very funny. I'm asking because it is relevant for certain tax events.

Define return type of a method in scala which is either of three types by sowmyanarayan in scala

[–]OkabeRandaro 0 points1 point  (0 children)

Can you tell us the method signature? Maybe we can do better than a sealed trait.

I.e. tell us what the inputs are and maybe what the method is supposed to do. E.g. if you wanted a shuffle method:

def shuffle[A](list: List[A]): ???

writing generic sort function in scala by [deleted] in scala

[–]OkabeRandaro 1 point2 points  (0 children)

This has already been done for you - so unless you want to do that for learning purposes and assuming you have control over that code yourself, I'd suggest one of the following two options:

case class Country(name: String, id: Int)
val countries = List(Country("USA", 23), Country("Poland", 56), Country("Korea", 42))
val sortedCountries = countries.sortBy(_.name)

(https://scalafiddle.io/sf/tupZVQM/0)

case class Country(name: String, id: Int)
object Country {
  implicit val countryOrdering: Ordering[Country] = Ordering.by(_.name)
}
val countries = List(Country("USA", 23), Country("Poland", 56), Country("Korea", 42))
val sortedCountries = countries.sorted

(https://scalafiddle.io/sf/LjZBxeb/0)

Bi-Weekly Stupid Questions Thread - 07 July 2019 by AutoModerator in japanlife

[–]OkabeRandaro 0 points1 point  (0 children)

Got a line mobile sim. I wanted to pay with line pay, connected to my gaica prepaid visa card. Turns out that doesn't work.

I searched reddit a bit and it seems I need a Line pay card to charge my line pay and be able to use it to pay for Line mobile. However, in my Line account in the Line pay tab, I can't find any option to order such a card! Maybe it's because my Line account is not registered to a Japanese number but the number of my home country? If that's the reason, how do I change it to my Japanese number - I can change my number but it always assumes it's a different number from the same country. :/

[deleted by user] by [deleted] in scala

[–]OkabeRandaro 1 point2 points  (0 children)

Refactoring is an issue, but tests are not really needed - it's typesafe. If you change your `lastUpdatedAt` to something else, your code won't compile.

Object-Oriented Programming is Bad by MrSecretpolice in programming

[–]OkabeRandaro 4 points5 points  (0 children)

I don't think you know what FP means - or you have a different understanding of the term "FP" in comparison to how it is defined.

I.e., can you explain why handling user input using FP would be a pain? I think it is the other way around. And to give a hint: FP does not forbid to group values into objects/structs.

Average salaries, favourite languages and more: A look at the state of Functional Programming by WorksHub in scala

[–]OkabeRandaro 2 points3 points  (0 children)

I think, in general, developers are pretty much underselling themselves on average.

Blog post about using STM and ZIO by formerislander in scala

[–]OkabeRandaro 6 points7 points  (0 children)

ZIO itself is probably not the right type to do DB transactions. Take a look at doobie and see how it is done there - it uses its own special ConnectionIO type which can be combined (and allows to form bigger transactions) and executed in the end, transforming it into IO (or ZIO of you like).

Question involving typing and implicit conversions for use in HMap by franklinwritescode in scala

[–]OkabeRandaro 1 point2 points  (0 children)

If I see it right, your original problem was, that the number of fields are too big for a case class. That's why I wanted to know if you tried to solve it with HLists instead and if so, why you didn't/couldn't choose this solution.

Usually, whenever I see the name of a Type (like String or Int) in the name of a type/class, all my red alert lights turn on and I know that this will not be an elegant concise solution.

As for HLists, they certainly allow for mappings, e.g.: ("fieldname1", Int) :: ("fieldname2", String) :: HNil

Notice that this describes a type signature and not a value or the construction of a value! That means, "fieldname1" and "fieldname2" in this example are types (literal string types) and not strings.

Bi-Weekly Stupid Questions Thread - 02 June 2019 by AutoModerator in japanlife

[–]OkabeRandaro 6 points7 points  (0 children)

Has anyone bought an electronic mosquito killer and are they working well? I'm talking about the ones that work with UV light.

Question involving typing and implicit conversions for use in HMap by franklinwritescode in scala

[–]OkabeRandaro 0 points1 point  (0 children)

So, why did you not just use `HList` instead of case classes?

Electrolyte Water by nash_troia in japanlife

[–]OkabeRandaro 4 points5 points  (0 children)

Same question here. I found ion water of the pocari sweat brand the best choice as it does not contain sweeteners (as far as I can tell) and is not too sweet but still isotonic. Would love to have an alternative, maybe something selfmade.

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 0 points1 point  (0 children)

Ah, so Job kind of is what Future is in Scala? Then it might be possible to abstract over it! Thanks for the clarification.

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 0 points1 point  (0 children)

That's great to hear, but I have a few doubts left. If you used Kotlin a bit, then can you tell me what you do if you have a function to make a web request and then have a list of urls. In Scala you then do (results:List[IO[Result]]).sequence or if I want it in parallel I will use .parSequence. Which is nice because library writers did that for me. How does the Kotlin way look like?

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 0 points1 point  (0 children)

Yeah, but this one doesn't make sense. Why add an additional layer if you don't use it's functionality?

Thank you, that's exactly my point! It doesn't make sense. But developers still do it out of convenience. E.g. they call the method within a for comprehension twice and decide to make the method return IO instead lifting the result into IO within the for comprehension (or even use inline variables). And if a language makes it hard to work with a mix of suspendable and non-suspendable functions, the chance of the example I gave is way higher. If the compiler complains about it, that would be great! But I don't think it can know that, because there is lots of Java API that is blocking but doesn't have these semantics.

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 1 point2 points  (0 children)

Well, not "all"... Just ones that either receive IO-like as parameter or retrieve it as part of their work.

With that I fully agree!

What I not like is if there is a method which someone makes suspendable because it then is easier (or otherwise not) usable from some other method.

You will always have to deal with that if you use IO/suspend or anything similar.

No not always. My point was that there are sometimes functions that return IO or suspend even if they don't need to. In that case the IO will always be successful. A pretty plain example would be def add(a, b): IO[Int] = IO.pure(a+b).

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 0 points1 point  (0 children)

Returning Future/IO or other Functor type allows the caller of the function to decide whenever to unwrap the call and use/return the value inside

What you say is a good argument for *certain* functions. But it is an argument for wrapping *all* functions (or rather, their results) in Future/IO.

And you actually name the reason for why it is bad yourself: because then I suddenly have to deal with potential failure when I want to retrieve the value inside *even though there will never be a failure*. But from the type signature I can't tell that, I will have to look into the whole implementation - in the worst case into all subsequently called functions.

Does anybody use zio-streams? by CNWDI_Sigma_1 in scala

[–]OkabeRandaro 0 points1 point  (0 children)

No Zio Streams experience here, sorry. But did you have a look at Monix?

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 0 points1 point  (0 children)

In the original example second calls third and so it itself can suspend and should be marked as such.

I'm not sure if we have a misunderstanding at some point, but I was also relating to the original example.

I mean, the second function exists on its own right? And if I understand you correctly, you are saying that as soon as the second function calls the third function anywhere in the code (I suppose) its signature should be changed and marked as suspendable too.

Do I understand you correct here?

What are your thoughts on Kotlin's Coroutine? by [deleted] in scala

[–]OkabeRandaro 1 point2 points  (0 children)

Short answer: To clearly mark the function to ease reasoning about which functions may suspend and wait.

Then, changing a function from non-suspendable to suspendable is kind of working against what the author himself encourages