Skip to content

Commit 48fd464

Browse files
committed
Added sources jar to archives.
1 parent ac46efc commit 48fd464

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ dependencies {
2727
task sourcesJar(type: Jar, dependsOn: classes) {
2828
classifier = 'sources'
2929
from sourceSets.main.allSource
30+
}
31+
32+
artifacts {
33+
archives sourcesJar
3034
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.h0tk3y.kotlinMonads
2+
3+
fun json(block: JsonContext.() -> Unit) = JsonContext().run {
4+
block()
5+
"{\n" + output.toString() + "\n}"
6+
}
7+
8+
class JsonContext internal constructor() {
9+
internal val output = StringBuilder()
10+
11+
private var indentation = 4
12+
13+
private fun StringBuilder.indent() = apply {
14+
for (i in 1..indentation)
15+
append(' ')
16+
}
17+
18+
private var needsSeparator = false
19+
20+
private fun StringBuilder.separator() = apply {
21+
if (needsSeparator) append(",\n")
22+
}
23+
24+
infix fun String.to(value: Any) {
25+
output.separator().indent().append("\"$this\": \"$value\"")
26+
needsSeparator = true
27+
}
28+
29+
infix fun String.toJson(block: JsonContext.() -> Unit) {
30+
output.separator().indent().append("\"$this\": {\n")
31+
indentation += 4
32+
needsSeparator = false
33+
block(this@JsonContext)
34+
needsSeparator = true
35+
indentation -= 4
36+
output.append("\n").indent().append("}")
37+
}
38+
}
39+
40+
fun main(args: Array<String>) {
41+
val j = json {
42+
"a" to 1
43+
"b" to "abc"
44+
"c" toJson {
45+
"d" to 123
46+
"e" toJson {
47+
"f" to "g"
48+
}
49+
}
50+
}
51+
52+
println(j)
53+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.h0tk3y.kotlinMonads
2+
3+
val foo by lazy { "abc" }
4+
5+
var <T> List<T>.bar get() = foo; set(value) {
6+
println(foo)
7+
}

0 commit comments

Comments
 (0)