forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Bikeshed composability
Graydon Hoare edited this page Jan 6, 2012
·
1 revision
We should think about how to improve composability in Rust.
-
We should have
str::any()
andlist::any()
likevec::any()
. But why duplicate the implementation when they all simply expect a stream of values? -
vec::any2()
is likevec::any()
operating on two lists instead of one. In Haskell you would simply would doany foo $ zip ls
and would not need a special functionany2
. In Rustvec::zip()
creates a whole new vector, but we'd need something likevec::zip_iter()
that only iterates over the zipped-list => generates a stream of tuples.
Why were iterators ruled out? I think they would be ideal for composability.
- If we had something like
str::iterator() -> iterator<T>
,list::iterator() -> iterator<T>
,vec::iterator() -> iterator<T>
- we would only need one
any(iterator<T>) -> bool
- and could get rid of duplicate
str::any()
,list::any()
andvec::any()
as well anyvec::any2()
- imlpementation via type classes / interfaces