|
Could use some help in going from my comfortable OOP/imp Java style to Scala functional style. Basically, I have a stream of events coming in, all of which are one of a set of discrete types, and for every type we would like to have a set of "enhancement" functions executed based on the type. In Java, I'd probably just have created an "Event" class and extended that for each of the events, keeping a set of implementations of an "enhancer" function and overriding the "enhance" function in each Event extensions with the execution of all of the enhancers kept in that Set. I'm struggling a bit with how to structure this "properly" with Scala. Obviously I could probably implement it very similarly to how I did it in Java, but I don't know if that's the best method. On a similar note, while picking up syntax and understanding what's going on behind the scenes of Scala -> JVM code, picking up the functional paradigms has been hard for me.
|
# ¿ Mar 23, 2017 15:14 |
|
|
# ¿ May 14, 2024 14:38 |
|
Everything could return the same event type. Basically I need to turn a JSON record like {eventType, timestamp, key} into {eventType, timestamp, key, enhancement1, enhancement2, enhancement3} where those "enhancements" are just results of running the enhancement functions which range from a few calculations to lookups in local files.
|
# ¿ Mar 23, 2017 15:39 |
|
Is "cake pattern" the only way to mock out something like this? I need to mock out MaxmindDatabases.getConnectionTypeResult in a unit test but you can't mock objects. I guess another option is to create a companion object of the class and access it like that? I'm brand new to Scala so I really can't evaluate tradeoffs of such things too well.code:
|
# ¿ Mar 29, 2017 22:26 |
|
I'm half asleep right now so I'll give this a shot tomorrow but I think the thing tripping me up was that a few things I was trying to mock were Objects which can't be mocked as easily as classes. I have a parent class that has a function with an arbitrary number of Objects being called and those functions don't really make sense as classes because they'll never have any non-instance properties or anything so I made them Scala objects. I guess I could change everything to classes, expose via companion, and mock accordingly.
|
# ¿ Mar 30, 2017 06:04 |
|
What's the most efficient way in Scala to do pass a String through a number of possible regex pattern and match based on which pattern is matched?code:
|
# ¿ Jun 19, 2017 19:08 |