8 ms·
Kotlin 1.1: What’s coming in the standard library
- nemo1618 10y ago"onEach" looks helpful. I actually just added such a function to my own Go extension project, although I named it "tee". The benefit is that when you have a long chain of map -> filter -> reduce, you can insert a tee as a sort of "porthole" into the current state at any location in the chain. Very handy for things like debugging and logging.
- khc 10y agoit looks exactly like Java's peek(), not sure why they don't use the same naming.
- jorgemf 10y agoIt is not like java peek at all (or I am missing what peek do your refer to). Peek is to get the reference of the first element. OnEach makes a lazy operation for every element on the sequence. I would say that onEach is more like map but lazy.
- kevinherron 10y agoIt's just forEach that returns the collection/sequence instead of returning Unit. Don't overthink it. It's not like map.
- jorgemf 10y ago> On iterables it behaves like forEach but also returns the iterable instance further. And on sequences it returns a wrapping sequence, which applies the given action lazily as the elements are being iterated. like forEach and also returns the iterable instance or like map, it is the same. For me the key thing is that onEach applies lazily for sequences.
- kevinherron 10y agoNo, it's not like map. Map builds a new collection based on the function you provide it. At the end of a map call you end up with a potentially transformed collection instance.
- jorgemf 10y agoYou should consider change your tone when you talk to people. It is quite rude. It is not a map and it is not a forEach, that is why they created it. > At the end of a map call you end up with a potentially transformed collection instance The difference between onEach and map is that map returns a new collection that can have different type of elements. But onEach can modify the internal state of the objects when applied. Also onEach is lazy and map is not lazy in kotlin (as far as I know). Why did I make the comparison with map and not with forEach? Because forEach is basically a translation of a for and map is a functional function and onEach it is also a functional function. You can agree or disagree with my way of trying to explain things, but being rude in your comments saying you are not right (when I know) and them providing another solution that you also know it isn't right, feels like a troll comment.
- agumonkey 10y agoMay I describe it as an effectful identity ?
- khc 10y agoJava's stream has a peek(), which also makes a lazy operation for every element in the stream.
- jorgemf 10y agoI feel kotlin is a bit undervalue. It is a great modern language which can replace java completely. Along with swift, they should be the general purpose programming languages in the near future.
- chinhodado 10y ago> Along with swift, they should be the general purpose programming languages in the near future. Unfortunately that is not going to happen for Kotlin, unless it gets adopted by major projects, and by major I mean on the scale of Android. Java is not going anywhere soon. If anything, Kotlin will become a second Scala.
- jorgemf 10y agoWell, it is broadly used by Android developers. For me Kotlin is above scala just because the tooling support (JetBrains the main developers of kotlin), and I find a big difference when writting kotlin and scala. I feel scala more difficult to read, while kotlin is just a pleasure to read code. Moreover you can mix java and kotlin in the same project without issues. Why do you think it will be behind scala?
- chinhodado 10y agoI don't mean to say it will be behind Scala, I just mean to say that it will end up in the same situation as Scala, a language that was meant to be a "better Java" but could never gain enough traction to take off.
- jorgemf 10y agoWhen I used Scala I never though it would be better than java, just another alternative. But I think kotlin is better than java. I hope it gains traction but not sure about it.
- relics443 10y agoKotlin has a much smaller learning curve than Scala. I find it to be much more useful than any other language I've tried out. It has shiny, useful features like some of the more dynamic languages do, but it's close enough to Java that I'm comfortable using it.
- jpliska 10y agoKotlin has been useful to me and easy to learn. It dovetails so well with exisiting java libraries that no Kotlin revolution (rewrite everything) is necessary. The most notable frameworks are in android land (Anvil, Bansa -- like react, redux). But on the backend, you can use stardard stuff. That's why Kotlin has been well accepted but not made a huge splash.
- dimillian 10y agoCan I use it to code full featured modern Android application without Java?
- tn_ 10y agoWhile Kotlin itself is a nice modern swift-like language, it'll never get the same type of adoption unless Google makes it a priority. I'm a lead Android developer and I've inherited a Kotlin codebase mixed with Java, and here's why I refuse to create any new classes in Kotlin: 1). Compile-time is slow. I know there are plenty of work-arounds but I don't want to modify the build-properties to the point where it's hard to replicate when onboarding new engineers. The closer to the default-project settings, the better and the less resistance. Android dev itself is a very fragile framework to begin with. 2). Abuse with nullable types. I've been a lead iOS engineer too and this is what I have observed as well with Swift. I can't even count the amount of Crashlytic reports that have been caused by a model not binding properly. 3). It really doesn't save that much time at the end of the day. A language is a language is a language. 4). Community/docs does not have as much reach as Java in terms of docs. This speaks more to the previous developer than the language itself, but this has been the most unstable code-base I've ever worked with. I specifically avoid web-development for the bandwagoning hype when the shiniest new piece of tech comes out. While I think it's great that Jetbrains is trying to make a competitive language to Java, I think there are too many forces working against them. Java's old, boring and predictable, but that makes it a great language to a build a stable app with.
- ptx 10y ago> 2). Abuse with nullable type What kind of abuse? Too much or too little nullability? I mean, in Java anything can be null unless it's a primitive type, so that should give you even more problems. Unless it's some sort of mapping of nullable values to non-nullable types that's giving you these crashes?
- hota_mazi 10y ago> 3). It really doesn't save that much time at the end of the day. A language is a language is a language. That's a... surprisingly uninformed statement from a "lead" developer.
- tn_ 10y agoToo many engineers get caught up with the minor details of the syntax of a language and ignore the business implications of using an untested technology. My job as a lead is to help scale my team, properly architect the application as well as reducing any risk / uncertainty while delivering new features to the platform. The syntax doesn't save that much time in my personal experience. The actual amount of words that's typed might be less.. it can be cleaner than Java but if my team is spending a higher amount of time debugging Kotlin issues relative to working with the Java codebase then we've got a problem. --- > That's a... surprisingly uninformed statement from a "lead" developer. That's a... surprisingly snarky / unhelpful remark with no counter to my statement.