improving the join function
Daniel Gibson
metalcaedes at gmail.com
Mon Oct 11 18:09:39 PDT 2010
bearophile schrieb:
> Andrei:
>
>> One thing is still bothering me: the array output type. Why would the
>> "default" output range be an array?
>
> The chain() function that returns a range is already present.
>
>
>> What can be done to make join() at
>> the same time a general function and also one that works for strings the
>> way the old join did?
>
>> I also have a question from people who dislike Phobos. Was there a point
>> in the changes of signature above where you threw your hands thinking,
>> "do the darn string version already and cut all that crap!"?
>
> Too much over-generalization is bad, and not just for D newbies. So std.string may contain wrappers specialized for strings. You may implement a generic std.algorithm.join, and then implement the std.string.join that uses just strings (the second argument may be a single char too) and calls std.algorithm.join for its implementation.
>
> Bye,
> bearophile
I like that idea.
I don't like the name "join" - especially for general ranges.
When I hear join I think of database like joins. These may not be horribly interesting for strings
but certainly are for general ranges (*).
union() or concat() would be better names for doing what std.string.join does.
(*) Something like
Range!(Tuple!(T1, T2)) join(T1, T2)(Range!(T1) r1, Range!(T2) r2, BinaryPredicate!(T1, T2) joinPred)
just pseudo-code, I'm not really familiar with D2 and std.algorithm.
The idea is you have a Range r1 with elements of type T1, a Range r1 with elements of type T2 and a
predicate that gets a T1 value and a T2 value and returns bool if they match and in that case a
Tuple with those two values is part of the Range that is returned.
More information about the Digitalmars-d
mailing list