-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTTP adapters' features and generic node
- Loading branch information
1 parent
b849f9f
commit 9246f6c
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.hexagontk.core | ||
|
||
// TODO Other possible names: Struct or Record | ||
class Node(val pairs: List<Pair<String?, *>>) : List<Pair<String?, *>> by pairs { | ||
val list: Boolean by lazy { pairs.all { it.first == null } } | ||
val map: Boolean by lazy { !list } | ||
|
||
// constructor(items: List<*>) : this(items.map { null to it }) | ||
constructor(items: Map<String, *>) : this(items.map { (k, v) -> k to v }) | ||
// constructor(vararg items: Any) : this(items.asList()) | ||
constructor(vararg items: Pair<String, *>) : this(items.toMap()) | ||
|
||
private fun asMap(): Map<String?, *> = | ||
pairs.toMap() // Keeps last if duplicated key | ||
|
||
private fun groupMap(): Map<String?, *> = | ||
pairs.groupBy { it.first } | ||
} | ||
|
||
|
||
fun f() { | ||
Node( | ||
mapOf("a" to 1) | ||
) | ||
|
||
// Node( | ||
// listOf("a", 1) | ||
// ) | ||
|
||
Node("a" to 1) | ||
|
||
// Node("a", 1) | ||
// | ||
// Node( | ||
// "a", | ||
// 1, | ||
// Node( | ||
// "a" to "b", | ||
// "b" to true | ||
// ) | ||
// ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
http/http/src/main/kotlin/com/hexagontk/http/HttpFeature.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.hexagontk.http | ||
|
||
/** | ||
* TODO To be used in clients/servers (take advantage in tests to fire only tests that apply) | ||
*/ | ||
enum class HttpFeature { | ||
MULTIPART, | ||
COOKIES, | ||
ZIP | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters