Drakontas
Drakontas
MModular
Created by Helehex on 8/5/2024 in #community-showcase
Thermo
this is awesome! what do you use to render this onto a window?
57 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
yeah, this 100% needs parameterized traits, no way around it
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
oh i see, because the T in __next__ may not necessarily be the same T as the one from ListDatapipe
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
and then also removed the [T] from the required traits
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
I made __next__ in the trait take an inout self, copied the parameters onto __next__ impl, and then made that one inout self as well since it mutates self.index
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
My mojo -v is 24.4, so ref[_] doesn't parse for me yet, feel free to add it back in:
trait IterDataPipable:
fn __next__[T: CollectionElement](inout self) -> Optional[T]: pass

@value
struct ListDatapipe[T: CollectionElement](IterDataPipable):
var src: List[T]
var index: Int

fn __init__(inout self, src: List[T]):
self.src = src
self.index = 0

fn __init__(inout self, src: List[T], index: Int):
self.src = src
self.index = index

fn __iter__(self) -> Self: return self

fn __next__[T: CollectionElement](inout self) -> Optional[T]:
self.index += 1
if self.index == len(self.src) + 1:
return Optional[T](None)

return Optional[T](self.src[self.index - 1])

fn __len__(self) -> Int: return len(self.src) - self.index
trait IterDataPipable:
fn __next__[T: CollectionElement](inout self) -> Optional[T]: pass

@value
struct ListDatapipe[T: CollectionElement](IterDataPipable):
var src: List[T]
var index: Int

fn __init__(inout self, src: List[T]):
self.src = src
self.index = 0

fn __init__(inout self, src: List[T], index: Int):
self.src = src
self.index = index

fn __iter__(self) -> Self: return self

fn __next__[T: CollectionElement](inout self) -> Optional[T]:
self.index += 1
if self.index == len(self.src) + 1:
return Optional[T](None)

return Optional[T](self.src[self.index - 1])

fn __len__(self) -> Int: return len(self.src) - self.index
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
definitely something that needs parameterizable traits to make this easy
9 replies
MModular
Created by Josiah on 8/4/2024 in #questions
Difficult Trait Conformance
Might not be implementable except by moving [T: CollectionElement] parameter from ListDatapipe to every function of ListDatapipe, but you still run into the issue with var src: List[T]
9 replies