[Issue 9507] std.range.transposed behaves poorly with jagged ranges of ranges
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 3 17:35:48 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9507
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bearophile_hugs at eml.cc
--- Comment #1 from bearophile_hugs at eml.cc 2013-03-03 17:35:46 PST ---
(In reply to comment #0)
> If you pass a jagged range of ranges to std.range.transposed, once one of the
> subranges is consumed, .front will cause an invalid access to the empty
> subrange's .front, causing a runtime error.
>
> However, the returned range's .empty will still be false, even though you can't
> safely use .front anymore!
>
> So std.range.transposed should either return empty if *any* of its ranges are
> empty, or else, its .front should be modified so that empty subranges will be
> skipped over (or should there be an option to specify a default element?).
This shows some usages the stadard Haskell function transpose, I'd like the D
version to do something similar. No need for a default element:
Prelude> import Data.List (transpose)
Prelude Data.List> transpose [[1,2,3],[4,5,6],[7,8,9]]
[[1,4,7],[2,5,8],[3,6,9]]
Prelude Data.List> let a =
[[7,4,2,8,7],[8,0,8],[3],[1,6,0,7,7,2,0],[8,9,3,1],[6],[6]]
Prelude Data.List> transpose a
[[7,8,3,1,8,6,6],[4,0,6,9],[2,8,0,3],[8,7,1],[7,7],[2],[0]]
Prelude Data.List> transpose [[1],[],[3,4]]
[[1,3],[4]]
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list