Smartjava.org Website Review


Make info private

Traffic and Value

Is smartjava.org legit?
Website Value $383
Alexa Rank 1104825
Monthly Visits 4249
Daily Visits 142
Monthly Earnings $21.25
Daily Earnings $0.71
Click Here for Full Review


Smartjava.org Server Location

Country: Netherlands
Metropolitan Area: Not defined
Postal Reference Code: Not defined
Latitude: 52.3824
Longitude: 4.8995




Summarized Content

My name is Jos Dirksen, I currently work as independent contractor for Philips. I like talking, reading, presenting and writing about On this site you can find information on all the stuff I’m doing, writing or thinking about. If you have any questions feel free to I’ve recently made the effort to try and pick up Kotlin (again). The last couple of years I’ve been doing mostly scala work (with some other languages in between), and was wondering how the functional concepts of scala programming transfer to Kotlin. Main reason is that A couple of months ago the third edtion of my book on learning three.js was released: View on Packt. Just as for the previous examples I’ve put all the examples online so you can easily see what’s in the book, or just explore the samples, without the book. I just noticed that I never published the D3.js presentation I gave last year on Devoxx. So a bit late, but you can find the video for. 10 PRACTICAL KUBERNETES TIPS FOR DAY TO DAY KUBERNETES USAGE. A couple of years ago I wrote a number of articles on how to work with docker. Since that time a lot has changed in the docker and container world. Docker has ma*ured, and provides a large number of interesting features, accompanying tools and lots and lots of other Hi everyone, It’s been a whole two years since I posted stuff here, but as an early new year resolution, I decided to revive this blog, and share with you all the stuff I’ve been doing the last couple of years. As a start I’d like to share the presentation.. I’ve been very busy the last couple of months. Started a new project at Philips, started writing on D3.js for Packt, and besides that participating in two startups. So time to update this blog has been limited. While thinking about how to best present the voronoi


Smartjava Main Page Content

HTML Tag Content Informative?
Title: Welcome to Smartjava - Could be improved
Description: My name is Jos Dirksen, I currently work as independent contractor for Philips. I like talking, reading, presenting and writing about
H1: Welcome to SmartjavaIs it informative enough?
H2: Latest posts:Is it informative enough?

Other Helpful Websites and Services for Smartjava

Internal Pages

/page2/:
Title

Welcome to Smart a - Smart a - Page 2

[censored]

Description

My name is Jos Dirksen, I currently work as independent contractor for Philips. I like talking, reading, presenting and writing about technology

H1

Welcome to Smart a

[censored]

H2

Latest posts:

/books/:
Title

Overview of all my books - Smart a

[censored]

Description

Articles, books and stuff I find interesting

H1

Overview of all my books

/topics/posts/:
Title

posts - Smart a

[censored]

Description

Articles, books and stuff I find interesting

H2

Getting started with FP in Kotlin and Arrow: Typecl es

[censored]

/tags/:
Title

Tags - Smart a

[censored]

Description

Articles, books and stuff I find interesting

/content/kotlin-arrow-typecl [censorship] es/:
Title

Getting started with FP in Kotlin and Arrow: Typecl es - Smart a

[censored]

Description

I’ve recently made the effort to try and pick up Kotlin (again). The last couple of years I’ve been doing mostly scala work (with some other languages in between), and was wondering how the functional concepts of scala programming transfer to Kotlin. Main reason is that I don’t see myself returning to a any time soon but, Kotlin seems to fix many of the verbose parts of a. With the Arrow Kotlin also gets some FP concepts, so it looked like the right time to really dive into Kotlin, and see how FP in Kotlin holds up.We’ll just start this series with looking at how we can do typecl es using Arrow in kotlin. Before we start a quick note. In these examples I’ve used Gson for JSON marshalling, a better approach would probably have been using a more functional / immutable JSON library. So I might change that if I ever get the time for it.Setting up the environmentSince this is the first article, we’ll start with setting up the environment. I’ve just followed the instructions on Arrow, and ended up with the following gradle files:build.gradleplugins { id 'org.jetbrains.kotlin.jvm' version '1.3.0'}group 'org.smart a'version '1.0-SNAPSHOT'repositories { mavenCentral() jcenter() maven { url 'https://jitpack.io' } maven { url 'https://dl.bintray.com/spekframework/spek-dev' }}dependencies { testImplementation (org.spekframework.spek2:spek-dsl-jvm:$spek_version) { exclude group: 'org.jetbrains.kotlin' } testImplementation 'org.amshove.kluent:kluent:1.45' testRuntimeOnly (org.spekframework.spek2:spek-runner-junit5:$spek_version) { exclude group: 'org.junit.platform' exclude group: 'org.jetbrains.kotlin' } compile org.jetbrains.kotlin:kotlin-stdlib-jdk8 compile ch.qos.logback:logback-cl ic:1.2.3 compile io.ktor:ktor-gson:$ktor_version compile io.ktor:ktor-server-core:$ktor_version compile io.ktor:ktor-server-netty:$ktor_version compile io.arrow-kt:arrow-core:$arrow_version compile io.arrow-kt:arrow-syntax:$arrow_version compile io.arrow-kt:arrow-typecl es:$arrow_version compile io.arrow-kt:arrow-data:$arrow_version compile io.arrow-kt:arrow-instances-core:$arrow_version compile io.arrow-kt:arrow-instances-data:$arrow_version kapt io.arrow-kt:arrow-annotations-processor:$arrow_version compile io.arrow-kt:arrow-free:$arrow_version //optional compile io.arrow-kt:arrow-instances-free:$arrow_version //optional compile io.arrow-kt:arrow-mtl:$arrow_version //optional compile io.arrow-kt:arrow-effects:$arrow_version //optional compile io.arrow-kt:arrow-effects-instances:$arrow_version //optional compile io.arrow-kt:arrow-effects-rx2:$arrow_version //optional compile io.arrow-kt:arrow-effects-rx2-instances:$arrow_version //optional compile io.arrow-kt:arrow-effects-reactor:$arrow_version //optional compile io.arrow-kt:arrow-effects-reactor-instances:$arrow_version //optional compile io.arrow-kt:arrow-effects-kotlinx-coroutines:$arrow_version //optional compile io.arrow-kt:arrow-effects-kotlinx-coroutines-instances:$arrow_version //optional compile io.arrow-kt:arrow-optics:$arrow_version //optional compile io.arrow-kt:arrow-generic:$arrow_version //optional compile io.arrow-kt:arrow-recursion:$arrow_version //optional compile io.arrow-kt:arrow-instances-recursion:$arrow_version //optional compile io.arrow-kt:arrow-integration-retrofit-adapter:$arrow_version //optional compile org.jetbrains.kotlin:kotlin-script-runtime:1.3.10}compileKotlin { kotlinOptions.jvmTarget = 1.8}compileTestKotlin { kotlinOptions.jvmTarget = 1.8}apply plugin: 'application'apply plugin: 'kotlin-kapt'mainCl Name = 'io.ktor.server.netty.EngineMain'generated-kotlin-sources.gradleapply plugin: 'idea'idea { module { sourceDirs += files( 'build/generated/source/kapt/main', 'build/generated/source/kapt/debug', 'build/generated/source/kapt/release', 'build/generated/source/kaptKotlin/main', 'build/generated/source/kaptKotlin/debug', 'build/generated/source/kaptKotlin/release', 'build/tmp/kapt/main/kotlinGenerated') generatedSourceDirs += files( 'build/generated/source/kapt/main', 'build/generated/source/kapt/debug', 'build/generated/source/kapt/release', 'build/generated/source/kaptKotlin/main', 'build/generated/source/kaptKotlin/debug', 'build/generated/source/kaptKotlin/release', 'build/tmp/kapt/main/kotlinGenerated') }}gradle.propertieskotlin.code.style=officialktor_version=1.0.1arrow_version=0.8.1spek_version=2.0.0-alpha.2Note that if you want to use the annotation processing and you use Intellij Idea for development, you might run into the issue that no sources are being generated for the Arrow annotations. The reason is that Intellij uses it’s own system to build the sources, and not necessary your complete gradle file. This can easily be fixed though by changing enabling the following setting:At this point we should be able to use the annotations provided by Arrow and all the other provided FP functionality.Creating typecl esI’m just going to ume you already know what typecl es are. If not there are many resources out there that explain what they do and why they are really useful: Scala typecl explained: Implement a String.read function Wikipedia typecl explanation Cats: typecl es Haskell: typeclasesTypecl es are also often used to marshal types from JSON to a domain object and back again. So in this example we’re going to use that as the example. We’ll start with the interface definition of our marshallers:typealias Result = Eitherobject Marshallers { fun convertToJson(m: T, ev: JsonMarshaller): JsonElement = ev.run { m.toJson() } interface JsonMarshaller { fun T.toJson(): JsonElement companion object {} }}object Unmarshallers { fun convertFromJson(j: String, ev: JsonMarshaller): Result = ev.run { fromJson(j) } interface JsonMarshaller { fun fromJson(j: String): Result companion object {} }}Here you can see that we’ve defined an interface that can handle marshalling a T to a JsonElement and one that does the opposite. Unmarshal an incoming String to a Either. We’ve also added a helper method that takes an instance of a typecl and calls the relevant function. Before we look at implementations of these typecl es let’s take a quick look at a very simple model.object Model { data cl Product(val productId: String, val description: String) { companion object {} } data cl OrderLine(val lineId: Int, val quantity: Int, val product: Product) { companion object {} } data cl Order(val orderId: String, val orderLines: List) { companion object {} }}Create typecl instances for the marshallersThe first thing we’re going to do is define the marhsallers. The marshaller will take a T and convert it to a JSONElement. With Kotlin, creating this is pretty simple. Let’s start with the most simple approach. A quick note on this code and the code later on in the article. This is purely to demonstrate how typecl es work in Kotlin. In real code we would do this differently (especially use a different JSON library), so don’t look to much at the something convoluted code in the marshallers and the unmarshallers. val orderLineMarshaller = object : JsonMarshaller { override fun Model.OrderLine.toJson(): JsonElement { val orderLine = gson.toJsonTree(this).asJsonObject orderLine.add(product, Marshallers.convertToJson(this.product, MarshallerInstances.productMarshaller)) return orderLine } } val productMarshaller = object : JsonMarshaller { override fun Model.Product.toJson(): JsonElement = gson.toJsonTree(this) } val orderMarshaller = object : JsonMarshaller { override fun Model.Order.toJson(): JsonElement { val orderLines = this.orderLines.map { Marshallers.convertToJson(it, orderLineMarshaller) } val withoutOrderLines = this.copy(orderLines = listOf()) val json = gson.toJsonTree(withoutOrderLines) val f = JsonArray() val acc = orderLines.foldLeft(f) { res, el -> res.add(el); res} val result = json.asJsonObject result.remove(orderLines) result.add(customorderlines, acc) return result } }In this code fragment you can see that we create a numbr of instances of the JsonMarshaller interface. And use the Marshallers.converToJson function to convert the nested objects to JSON. We could of course also have used the gson.toJsonTree(this) call everywhere, but that wouldn’t have allowed us to easily customize the way the various objects are marshalled.Now lets set up a simple test to see what is happening when we run this code: describe(The product marshaller instance) { val product = Model.Product(product, description) it(should marshall an product to a JSON value) { val result = MarshallerInstances.productMarshaller.run { product.toJson().toString() } result `should be equal to` {productId:product,description:description} } } describe(The orderline marshaller instance) { val orderLine = OrderLine(1, 2, Model.Product(, )) it(should marshall an orderline to a JSON value) { val result = MarshallerInstances.orderLineMarshaller.run { orderLine.toJson().toString() } result `should be equal to` {lineId:1,quantity:2,product:{productId:,description:}} } } describe(The order marshaller instance) { val orderLines = listOf(OrderLine(1,2, Model.Product(, )), OrderLine(2,3, Model.Product(, ))) val order = Order(orderId, orderLines) it(should marshall an order to a JSON value) { val result = MarshallerInstances.orderMarshaller.run { order.toJson().toString() } result `should be equal to` {orderId:orderId,customorderlines:[{lineId:1,quantity:2,product:{productId:,description:}},{lineId:2,quantity:3,product:{productId:,description:}}]} } }All these tests p , since we’re just calling them directly. We can also use the function defined in the Marshallers object:fun convertToJson(m: T, ev: JsonMarshaller): JsonElement = ev.run { m.toJson() }...val orderLine = OrderLine(1, 2, Model.Product(, ))Marshallers.convertToJson(orderline, MarshallerInstances.orderLineMarshaller)The big advantage of calling it like this, is that the compiler checks for us that we’ve used the correct typecl instance. If we try to call this with a typecl instance of the incorrect type, the compiler starts complaining:val orderLines = listOf(OrderLine(1,2, Model.Product(, )), OrderLine(2,3, Model.Product(, )))val order = Order(orderId, orderLines)Marshallers.convertToJson(order, MarshallerInstances.orderLineMarshaller)This will fail:e: fskotlin/src/test/kotlin/org/smart a/typecl es/MarshallersSpecTest.kt: (51, 21): Type inference failed: Cannot infer type parameter T in fun convertToJson(m: T, ev: Marshallers.JsonMarshaller): JsonElementNone of the following substitutions(Model.OrderLine,Marshallers.JsonMarshaller)(Model.Order,Marshallers.JsonMarshaller)(Any,Marshallers.JsonMarshaller)can be applied to(Model.Order,Marshallers.JsonMarshaller)As you might have noticed, we have to p in the specific instance of the typecl that we want to use. I come from a scala background and am used to p ing in typecl es as implicit parameters (or use a context bounded type parameter). With that approach it is enough for the typecl to be (implicitly) in scope, so we don’t have to explicitly p it into the function. For Kotlin there is a proposal (KEEP-87), which proposes something similar. There is also a reference implementation available, that already allows you to play around with it. So in a future article I’ll do the same as in this article, but then with that implementation.Now let’s also quickly implement the unmarshallers to get back from JSON to Kotlin.Create typecl instances for the marshallersFor a very naive implementation of the unmarshallers we can create something like this:object UnmarshallerInstances { val gson = Gson() val parser = JsonParser() val productUnmarshaller = object : JsonUnmarshaller { override fun fromJson(j: String): Result = try { Either.right(gson.fromJson(j, Model.Product::cl . a)) } catch (e: Throwable){ Either.left(e) } } val orderLineUnmarshaller = object : JsonUnmarshaller { override fun fromJson(j: String): Result = try { // first use the productUnmarshaller to get a Result val jsonObject = parser.parse(j).asJsonObject val jsonProduct = jsonObject.get(product) val product = productUnmarshaller.fromJson(jsonProduct.toString()) // if product is right, convert it to a product, else we get the error. product.map{ p -> Model.OrderLine(jsonObject.get(lineId).asInt, jsonObject.get(quantity).asInt, p)} } catch (e: Throwable){ Either.left(e) } } val orderUnmarshaller = object : JsonUnmarshaller { override fun fromJson(j: String): Result = try { val jsonObject = parser.parse(j).asJsonObject val jsonOrderLines = jsonObject.get(customorderlines).asJsonArray // convert using the correct unmarsahller val orderLines = jsonOrderLines.map { ol -> orderLineUnmarshaller.fromJson(ol)} // now we've got a List. We'll reduce it to a Result when (res) { is Either.Left -> res is Either.Right -> when(ol) { is Either.Left -> ol // set the error is Either.Right -> Either.right(res.b.plus(ol.b)) } } } // and finally return the unmarshalled object orderLinesK.map{ ols -> Model.Order(jsonObject.get(orderId). tring, ols)} } catch (e: Throwable){ Either.left(e) } }}Without going into too much detail here. You can see that we do some custom JSON unmarshalling here to convert our custom generated JSON back to our data cl es. The productUnmarshaller is really straightforward, and we just use the standard gson unmarshall functionality. For the orderLineUnmarshaller we reuse the productUnmarshaller and use the map function to creae a OrderLine is the Product was parsed successfully. And for the complete order, we reuse the orderLineUnmarshaller to convert the incoming data to a List. We fold this into a Result Model.OrderLine(jsonObject.get(lineId).asInt, jsonObject.get(quantity).asInt, p)} } catch (e: Throwable){ Either.left(e) } }As you can see not that much has changed. The main thing that has changed is that we now define an interface, and not an val or fun. What Arrow does, it will generate code that looks like this:package org.smart a.fskotlin.orderline.jsonUnmarshallerimport arrow.core.Eitherimport kotlin.Stringimport kotlin.Suppressimport kotlin.Throwableimport kotlin.jvm.JvmNameimport org.smart a.fskotlin.Model.OrderLine.Companionimport org.smart a.fskotlin.OrderLineimport org.smart a.fskotlin.OrderLineUnmarshallerInstance@JvmName(fromJson)@Suppress( UNCHECKED_CAST, USELESS_CAST, EXTENSION_SHADOWED_BY_MEMBER, UNUSED_PARAMETER)fun fromJson(j: String): Either = org.smart a.fskotlin.Model.OrderLine .jsonUnmarshaller() .fromJson(j) as arrow.core.Eitherfun Companion.jsonUnmarshaller(): OrderLineUnmarshallerInstance = object : org.smart a.fskotlin.OrderLineUnmarshallerInstance { }As you can see this will create an OrderLineUnmarshallerInstance on the companion object of the OrderLine cl , so we can easily access it, and create a helper function for easy access to the fromJson function. Throughout the Arrow code base this is used extensively, which is a good thing, to make sure that all the typecl es follow the same pattern. For your own projects, I don’t think you should need this, and it’s probably easier and more straightforward to just define the typecl es directly and ign them to a fun or a val.Use Arrow functionality: Foldable typecl Before ending this article, I want to clean up a couple of code fragments by using some other arrow typecl es. The first one is the orderMarshaller: val orderMarshaller = object : JsonMarshaller { override fun Model.Order.toJson(): JsonElement { val orderLines = this.orderLines.map { Marshallers.convertToJson(it, orderLineMarshaller) } val withoutOrderLines = this.copy(orderLines = listOf()) val json = gson.toJsonTree(withoutOrderLines) val f = JsonArray() val acc = orderLines.foldLeft(f) { res, el -> res.add(el); res} val result = json.asJsonObject result.remove(orderLines) result.add(customorderlines, acc) return result } }While this works, it isn’t the best way to do this. We first have to explicitly map the orderLines to a List, we can’t use this list directly, but have to convert it again to a JsonArray, before we can use it. What would be nice is if we could have a JsonMarshaller which would be able to automatically marshall a list or set of T to a JsonArray. If we look at the previous code what we need to do is some mapping from T to a JsonElement and some folding. To go from T to JsonElement we’ve already got out JsonMarshaller, and Arrow provides a typecl called Foldable that allow us to fold over a specific container. With these two typecl es we can create a JsonMarshaller instance that is able to create the JsonArray for arbitrary foldable containers like this: /** * For the type of Kind e.g ListK we can automatically fold them using the provided typecl . What * we need to know is evidence that it's foldable, and evidence on how to apply the marshaller to the embedded T * elements. */ fun foldableToJsonArrayMarshaller(fev: Foldable, ev: JsonMarshaller) = object: JsonMarshaller { override fun Kind.toJson(): JsonElement = fev.run { foldLeft(JsonArray()) { b, a -> b.add(ev.run { a.toJson() }) b } } }Here we use the provided foldable, to invoke foldLeft on the container, and the provided marshaller to convert the T elements contained in the foldable to a JsonElement. All the converted Ts are aggregated into a JsonArray, which is returned. Ignore the Kind stuff for now, since that is something for a different article. It is enough to know for now, that this is the way Arrow allows us to use higher kinded types for extensions. With this generic marshaller, we can now also change the orderMarshaller to something like this: val orderMarshaller = object : JsonMarshaller { override fun Model.Order.toJson(): JsonElement { val json = gson.toJsonTree(this.copy(orderLines = listOf())).asJsonObject val orderLinesJson = MarshallerInstances.foldableToJsonArrayMarshaller(foldable(), orderLineMarshaller).run { ListK(orderLines).toJson() } json.remove(orderLines) json.add(customorderlines, orderLinesJson) return json } }And you can see that we use the foldableToJsonArrayMarshaller and p in a foldable() which can be retrieved from the List companion object, and our marshaller. The rest is done in the same way as for the other typecl es. This makes our code much more clean, and if we have other containers with T elements, we can reuse this foldableToJsonArrayMarshaller marshaller.ConclusionAll in all it isn’t that hard to use and create typecl es in Kotlin. With Arrow we get a lot of functionality, that makes functional programming, working with monads and typecl es much easier. What you do see is that in certain parts the standard library of Kotlin is limited. Pattern matching is limited, and the lack of implicit arguments in functions makes using typecl es kind of intrusive. Besides that, the lack of a good API on top of immutable collections in Kotlin makes me miss standard functionality in other functional languages.But, Arrow in itself looks great. While it takes some effort to get my head in the right place, the provided type and data cl es work as expected (so far) and I’ll continue experimenting with the various parts to see how Arrow and Kotlin can work together.

[censored]

H1

Getting started with FP in Kotlin and Arrow: Typecl es

[censored]

H2

Setting up the environment

H3

Jos Dirksen

All the information about smartjava.org was collected from publicly available sources

Similar domain names

snapcheat1.comupdate-manualsmartjavascript.comsmartjawalapps.comsmartjawreconstruction.comsmartjava.netsmartjav.comsmartjato.com



CAPTCHA ERROR
Recent Comments
Ronald Kurtz about trimbodymax.com
You took 89.95 and 84.95 at the same time from my back account that i didnt authorize and was apparently hacked. I...
Ester Joseph about repassists.com
Please refund my money back I never knew this am not interested
Jose Chavez about spoosk.com
Ive been charged for no reason this is fraud and want my money back!
CHANTREA BO about sitetaskreps.com
Good morning, Can you tell me what i have been charged for on 10/8/19 amount of $61..90 I believe this could be...
Leo Wickers IV about dotabon.com
Stop charging my account or police and better business bureau will be notified
tangi muzzo about attrdte.com
I need the money tht you took from my account.. I have no idea of what this site is all about.. Please return my...
Mthetheleli Peter about feemyd.com
This is a fraud I want my money back
motonobu matsubara about talentbrainstore.com
Please refund my 100yen and 10,000yen you took fraudulently as I never purchased or joined your site. Please cancel...
Selwyn Clarke about cartplay.com
Hi I sent an e-mail to you Thursday (nz) time and as yet I have had no response the number referred to is...
Nicolash Fernandes about ddos-guard.net
Knowing how reliable and secure DDoS protection service from ddos-guard.net, I have updated my plan with them and...
John about webtermdata.com
You have charged my credit card for $54.56 please add it back and cancel my subscription card ending 6485
DMCA.com Protection Status