Christian Dräger
04/22/2021, 5:44 PMfoo { // will invoke some object as this
0 {
// create some list based on Foo and get 0 index of list
}
* {
// create some list based on Foo and get all entries of list
}
}
https://kotlinlang.org/docs/operator-overloading.htmlnanodeath
04/22/2021, 5:47 PMnanodeath
04/22/2021, 5:47 PMnanodeath
04/22/2021, 5:47 PMnanodeath
04/22/2021, 5:48 PM+
I presume?nanodeath
04/22/2021, 5:51 PMChristian Dräger
04/22/2021, 5:52 PMChristian Dräger
04/22/2021, 5:52 PMnanodeath
04/22/2021, 5:52 PMfoo { // will invoke some object as this
0 {
// create some list based on Foo and get 0 index of list
}
* {
// create some list based on Foo and get all entries of list
}
}
I'm waiting for a build 😛nanodeath
04/22/2021, 5:53 PMn
or all
instead of *
Christian Dräger
04/22/2021, 5:58 PMfindAll
.
but wenn you need to use it a lot it feels a bit clumsy.
here is a the real world example.
https://github.com/skrapeit/skrape.it#parse-and-verify-html-from-string
instead of findFirst you can already invoke an Int to find matching elements by index
calling unary times would feel like the natural consequence to me. espacially in the context of css query selectors to pick html elements from a html documentnanodeath
04/22/2021, 6:00 PMfind * {
and made *
an infix operator?Christian Dräger
04/22/2021, 6:00 PMChristian Dräger
04/22/2021, 6:00 PMnanodeath
04/22/2021, 6:01 PMChristian Dräger
04/22/2021, 6:04 PMhtmlDocument("""
<html>
<body>
<h1>welcome</h1>
<div>
<p>first p-element</p>
<p class="foo">some p-element</p>
<p class="foo">last p-element</p>
</div>
</body>
</html>""") {
h1 {
find 0 {
text toBe "welcome"
}
p {
withClass = "foo"
find 0 {
text toBe "some p-element"
className toBe "foo"
}
}
p {
find * {
text toContain "p-element"
}
findLast {
text toBe "last p-element"
}
}
}
}
thx for the great ideaChristian Dräger
04/22/2021, 6:06 PMnanodeath
04/22/2021, 6:08 PMChristian Dräger
04/22/2021, 6:16 PMnanodeath
04/22/2021, 6:20 PMnanodeath
04/22/2021, 6:21 PMnanodeath
04/22/2021, 6:21 PMnanodeath
04/22/2021, 6:21 PMnanodeath
04/22/2021, 6:21 PMChristian Dräger
04/22/2021, 6:22 PMnanodeath
04/22/2021, 6:22 PMNir
04/22/2021, 7:06 PMinfix
exists is exactly to avoid the need to add lots of symbols with relatively low usage. Traditionally, people have used operators a lot in DSL's in weird ways, mostly just because they wanted infix really badly.Christian Dräger
04/22/2021, 7:14 PMYoussef Shoaib [MOD]
04/24/2021, 6:34 AM