Info

Login

Channels

APIs

Credits

  • cheeser
  • ernimril
  • joed
  • kinabalu
  • lunk
  • ojacobson
  • r0bby
  • ThaDon
  • ricky_clarkson
  • topriddy

« 2021-02-21

2021-02-22

2021-02-23 »

Nick Message Date
Ladicek [Ladicek!~lthon@109.164.63.38] has joined #kotlin [01:41]
raoul11 [raoul11!~raoul11@unaffiliated/raoul11] has joined #kotlin [01:49]
ufobat [ufobat!~martin@dynamic-095-114-061-097.95.114.pool.telefonica.de] has joined #kotlin [02:13]
a0 [a0!~nanoz@gateway/tor-sasl/nanoz] has joined #kotlin [02:15]
Matthijs [Matthijs!~quassel@unaffiliated/matthijs] has joined #kotlin [02:29]
the_impaler84 [the_impaler84!~the_impal@pluto.redwill.se] has joined #kotlin [02:34]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [02:36]
CookE[] [CookE[]!~nanoz@gateway/tor-sasl/nanoz] has joined #kotlin [02:40]
CookE[] [CookE[]!~nanoz@gateway/tor-sasl/nanoz] has joined #kotlin [03:07]
rayyyy [rayyyy!~nanoz@gateway/tor-sasl/nanoz] has joined #kotlin [03:12]
rayyyy parted the channel: [03:16]
silverbaq [silverbaq!~silverbaq@062066150157.static.telenor.dk] has joined #kotlin [03:52]
lankanmon [lankanmon!~LKNnet@cpeb4fbe4e331bd-cm64777d632380.cpe.net.cable.rogers.com] has joined #kotlin [04:33]
Lengsdorfer [Lengsdorfer!~Lengsdorf@unaffiliated/lengsdorfer] has joined #kotlin [05:22]
varbhat [varbhat!varbhatmat@gateway/shell/matrix.org/x-kclxixoqmegpxmyn] has joined #kotlin [05:51]
argo [argo!~argo@unaffiliated/argo] has joined #kotlin [05:55]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [06:02]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [06:08]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [06:12]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [06:16]
liefer4 [liefer4!~liefer@unaffiliated/liefer] has joined #kotlin [07:08]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [07:32]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [07:38]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [07:47]
w0x12ef [w0x12ef!~textual@114.246.35.142] has joined #kotlin [07:56]
Ladicek [Ladicek!~lthon@109.164.63.38] has joined #kotlin [07:59]
crabskuttles [crabskuttles!~crabskutt@223.204.217.217] has joined #kotlin [08:03]
phaleth [phaleth!~phaleth@unaffiliated/phaleth] has joined #kotlin [10:28]
FuzzyBottom [FuzzyBottom!~FuzzyBott@d207-216-62-240.bchsia.telus.net] has joined #kotlin [11:03]
retroguy8000 [retroguy8000!~retroguy8@2804:14d:7683:80b3:8ca5:1ca4:98e2:3d3d] has joined #kotlin [11:17]
retroguy8000 [retroguy8000!~retroguy8@2804:14d:7683:80b3:8ca5:1ca4:98e2:3d3d] has joined #kotlin [11:23]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [11:30]
DTZUZU_ [DTZUZU_!~DTZUZU@207.81.119.43] has joined #kotlin [11:37]
DTZUZU__ [DTZUZU__!~DTZUZU@205.ip-149-56-132.net] has joined #kotlin [11:38]
FuzzyBottom Hello. Noob here. I am trying to learn how to work with enums and data classes. Is there a way to take an enum class with parameters, and call a data class using the enum as one parameter, to create a map of the enum parameters? Might be confusing how I worded it. [11:55]
FuzzyBottom So if enum class was Fruit (val: Name, val: Shape, val: Colour), to make a map of it in a data class calling data class GetFruit(val fruit: EnumMap<Fruit>) [11:58]
FuzzyBottom sorry, the : is in the wrong spot... [11:58]
FuzzyBottom Fruit val Name: String etc etc [11:58]
cheeser an enum class can't have parameters... [12:02]
cheeser type parameters anyway. [12:02]
FuzzyBottom Maybe I worded it wrong. According to what I see online, you can do this: enum class CardType(val color: String) [12:04]
FuzzyBottom so I would want to create a map that takes all of the ones listed, and set it as a map. Maybe it cannot be done. It's beyond my knowledge :) [12:05]
FuzzyBottom So if the types were ORANGE(colour = orange, shape = round, price = 1.00. It would take those and make a map from that [12:06]
cheeser you want a map of the fields on an enum instance? [12:12]
FuzzyBottom yes. See, I worded it wrong :) [12:13]
cheeser trying [12:13]
cheeser What are you trying to do? [12:13]
FuzzyBottom So if I have the user created calling the Person data class, and it would create a user that could have the fields of fruit available at creation of the user. So bob.ORANGE.price would be available at user creation [12:16]
cheeser you realize there's one instance of ORANGE for the whole system, right? you can't have varying prices between users or over time. [12:17]
FuzzyBottom Oh, no I did not. I thought if person 1 changed price, then it would not affect person 2. Perhaps that's why I cannot make it work :) [12:17]
cheeser yeah. enums are instantiated for you by the JVM so you get exactly one copy of each enum instance. [12:18]
cheeser enum class Fruits { APPLE, BANANA, ORANGE } // only 3 instances created here [12:19]
FuzzyBottom bbiab, sorry. [12:19]
cheeser sounds like you need orange to be a regular class [12:19]
zutat [zutat!02f31615@unaffiliated/zutat] has joined #kotlin [12:21]
orbyt_v7 [orbyt_v7!~textual@172.92.4.78] has joined #kotlin [12:43]
FuzzyBottom Hello again. Sorry about the delay... [12:51]
FuzzyBottom So if I wanted to have various prices, then I would have to create a class for each fruit? [12:52]
FuzzyBottom I spent 27 years networking and hardware. Trying to learn code is way more frustrating... [12:52]
FuzzyBottom Plus being almost 50 doesn't help :) [12:53]
cheeser you'd create a class called Fruit, say. [12:53]
cheeser it might look like this: class Orange(price: Double): Fruit("orange", price) [12:54]
cheeser then you could say: bob.fruit = Orange(45.0) [12:54]
FuzzyBottom Okay. So the enum would look like Fruit(val name: String, val price: Int)? Would there be any way to have it so if I wanted to add a new fruit to the enum that any place that listed the fruits to choose from would need updating (the when statemtents etc)? I would assume then that if I made a change to the enum, then things would show an error, and I could create the new fruit class. [12:59]
cheeser no enums involved. [12:59]
FuzzyBottom Oh, so enum free. Okay. [01:00]
FuzzyBottom Sorry if I sound ignorant... [01:00]
cheeser ignorance is just a lack of knowledge. easily fixable and nothing to apologize for. [01:01]
FuzzyBottom so perhaps enum classes are not something I am ready for. I was working with them and data classes, but might need to read more about them. I really appreciate your time. [01:01]
cheeser enum classes are good for modeling a fixed set of instances. the canonical example *there* would be suits in a deck of playing cards. [01:01]
cheeser you could model a fruit's *type* using an enum but there are hundreds/thousands of fruits and so that would be cumbersome at best. [01:02]
FuzzyBottom Well that I understand. I was just using that as a testing idea for learning how they all interacted with each other. [01:03]
cheeser and the instances of a enum are fixed at compile time so you couldn't add a new type of fruit at enum should you, e.g, open up a new market in Indonesia with all kinds of lovely new fruits you'd never heard of in Brighton. [01:03]
FuzzyBottom Ah, that is something I never knew, albeit it sounds logical... [01:04]
FuzzyBottom So another question then, would creating a map of fruits be the best idea? [01:04]
cheeser enums are great but not exactly general purpose [01:04]
cheeser well, "best" outside of a context is hard to nail down. would it work for your sample app? possibly. would I build one if I were building an online fruit exchange? probably not. [01:05]
FuzzyBottom Although FAR beyond my scope of knowledge ATM, what would be the best way to create a package like that? [01:06]
FuzzyBottom Using your market in various parts of the world so to speak [01:06]
FuzzyBottom I assume learning how to code databases [01:07]
cheeser i would have a database ... table (I tend to use mongodb so it'd be a collection) with all the fruits in the system [01:07]
FuzzyBottom Okay. I will have to wait until I get these basics down first. DB was something I did not like working with, even as a network/hardware guy. [01:08]
FuzzyBottom I really appreciate your help here [01:08]
FuzzyBottom Thank you again. [01:08]
cheeser np. it's why i'm here. :) [01:11]
FuzzyBottom I ams sure I will be here asking a lot of basic questions, so please do not get frustrated if I do. I will do my best to exhaust my online searches before doing so. [01:13]
cheeser sounds like a plan to me. that's all i ask. i'm happy to help those willing to put in the work. [01:20]
FuzzyBottom I tested what you were talking about, and I am glad I asked. I tried creating a second user, and yes, the values all changed when one changed. I played that differently in my head. [01:22]
cheeser nods. [01:22]
cheeser i could see you heading down that path. :) [01:22]
cheeser that fruit we be getting The Rogers Rate. ;) [01:23]
FuzzyBottom I remember clients telling me what was happening, and before they even were close to finish, I knew the problem. I can see that's your level in this field. HOPEFULLY I will get there one day. [01:25]
FuzzyBottom Mind you, I feel learning this trade at 50 might be a bit harder than when I made the choice to leave learning to code, to get into hardware when I was 24 :) [01:26]
cheeser just remember: programming is fundamentally problem solving. coding is just the syntax to write out those solutions. [01:27]
cheeser syntax is super easy. [01:27]
FuzzyBottom I find remembering the hardest. I can read most of the code I see and understand it, and then stare at the screen trying to implement something. I see that is quite common on some of the videos I have watched on people talking about their learning experience. It actually made me feel better knowing it was not just me and being old. [01:30]
FuzzyBottom Some say they have the "Aha" moment, and it starts to work. I am still waiting. Mind you, it's only been a couple of months at most, so I assume that will come someday :) [01:31]
cheeser yep [01:32]
Lengsdorfer [Lengsdorfer!~Lengsdorf@unaffiliated/lengsdorfer] has joined #kotlin [02:25]
Mrbuck [Mrbuck!~Mrbuck@gateway/tor-sasl/mrbuck] has joined #kotlin [02:46]
FuzzyBottom Okay, another question that I have. I now understand enums for what I was trying is not the way to go, but as I am still trying to understand how it all ties together, I would still like try something. If I have an enum class for a listing of fruit, and I want the user to be able to select a choice of the fruits listed in the enum (a for loop listing the items along with a # beside it), is there a way to convert the number [02:55]
FuzzyBottom selected to a matching enum value (when expression) that will flag if I add a new fruit to the enum list? Enumss and sealed classes do not need the "else" at the end of it, and if I do something like val selectedFruit = when(<number selected>) 1 -> Fruit.OORANGE etc, I would not want an else statement. [02:55]
FuzzyBottom Again, maybe not possible with how something works in my head, and how it actually works in the real world. [02:56]
RedNifre What's the best way to read YAML in Kotlin? [03:25]
squirrel snakeyaml works for me [03:43]
cheeser yep [03:52]
squirrel FuzzyBottom: > that will flag if I add a new fruit to the enum list what's that mean [03:56]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [04:00]
FuzzyBottom Oh, sorry. If I added a new fruit to the enum list, anywhere I was using a when statement that calls the enum list (I might be saying it wrong), if there is a change to the enum class, then the IDE would mark anywhere the new addition needed to be updated with an underline or something (I am using intellij) [04:00]
FuzzyBottom It might be that what I am trying to do would never be implemented in the real world, and I am wasting my time, but I am just trying to see how I can tie a data class to an enum class, and then call it using a function that allows you to create a user with a selected fruit type from the enum class with the values. I changed the enum class already, as Cheeser suggested. [04:03]
FuzzyBottom One can feel pretty inferior trying to learn this :) [04:03]
cheeser yes. if you're using a when with enums, you need to have exhaustive code paths: either a clause for each enum instance or a default clause to catch anything unmatched. [04:06]
squirrel FuzzyBottom: there's annotations like @IntRange but it's super niche [04:10]
FuzzyBottom Yes, I do understand that, but I am wondering if it is possible to have (for example) a for loop list the fruits in the enum class (all console at this point in my coding life), and a number beside it. If you select 1 -> Fruit.ORANGE or whatever. being an enum class, I thought you did not need an 'else' statement. [04:11]
FuzzyBottom squirrel: I was trying to learn those. A WEE bit above my knowledge at this point :) [04:12]
FuzzyBottom I am thinking at this point I should stop trying to work with for loops with enum class listings :) [04:13]
squirrel i can't imagine a non esoteric real life scenario with this issue. either i'm using a when with an enum or i want that else [04:16]
FuzzyBottom That's probably where I am messing up. I am probably doing something that would not work to start with. I guess I am wondering if there is a way to convert an int (the number of the selected fruit from the for loop printing the enum class items) into the when statement of 1 -> Fruit.ORANGE etc. Again, probably wording it wrong, and it's a non-issue with real programming knowledge. [04:21]
squirrel where's the 1 coming from? [04:21]
FuzzyBottom Sorry, if I had a for loop print off the items in the enum class, and a number beside it. So something like: var count = 1 for(i in Fruit.values()){println("$count: $i.toString() [04:26]
FuzzyBottom if there is five items in the enum class, is there a way to get the user input of the number (int) they selected, and with the when statement change it to the enum choice Fruit.ORANGE and not need an else statement? If the variable for the selected fruit was say "selectedFruit", if I use when(selectedFruit) the when statement always wants an else statement, and if I added a new fruit to the enum, it would not warn me that I need [04:29]
FuzzyBottom to update the when statement, as there is an else [04:29]
FuzzyBottom again, probably something that does not work, and I am frustrating to people like you :) [04:30]
cheeser with "when" you need a branch for every enum value. or an else. [04:31]
FuzzyBottom Yes, and that is where I am messing up. I will just leave this alone for now. I am sure, like the enum class issue you helped mw with, what I am trying to do, would not work. I just am frustrated with this learning curve :) [04:33]
cheeser the views are always better from the top. keep at it. ;) [04:33]
FuzzyBottom I really appreciate you both trying to help me out [04:33]
squirrel i mean, you are converting an int into enum. if it's coming from command line or protocol or w/e you need the else. if not, why do you need to convert [04:33]
FuzzyBottom From the bottom up, it seems quite the hike :) [04:34]
FuzzyBottom I understand more now how my clients must have felt when I would explain things to them, and they had that blank look in their eyes :) [04:36]
squirrel naming things, and trying to understand other programmers. the two primary lines of job of every programmer [04:39]
FuzzyBottom I long for the day those are my biggest issues :) [04:41]
FuzzyBottom Thank you both again for helping me. I do appreciate it. [04:41]
cheeser np [04:43]
FuzzyBottom I realised that my 'when' condition is the int selected, and not the enum itself, hence the need to have the 'else' statement. I knew that, but never really knew how to fix it. I will work on that next. Sorry for the confusion. I am probably wording that wrong too :) [05:16]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [05:24]
squirrel no need to be sorry, it's cool [05:24]
ricky_clarkson [ricky_clarkson!~rjclarkso@unaffiliated/rickyclarkson/x-000000001] has joined #kotlin [07:24]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [07:33]
orbyt_ [orbyt_!~orbyt@172.92.4.78] has joined #kotlin [09:25]
the_impaler844 [the_impaler844!~the_impal@pluto.redwill.se] has joined #kotlin [10:12]