On Tue, Jan 31, 2017 at 01:17:12PM +0100, Tomáš Golembiovský wrote:
On Tue, 31 Jan 2017 11:35:01 +0000
"Richard W.M. Jones" <rjones(a)redhat.com> wrote:
> On Mon, Jan 30, 2017 at 10:43:15PM +0100, Tomáš Golembiovský wrote:
> > Added two new optional arguments to nsplit:
> >
> > * keep_empty: if set to false empty elements are not stored in the
> > returned list. The default is to keep the empty elements
>
> The ?keep_empty flag is pointless. It's simpler and more
> clear to write:
>
> List.filter ((<>) "") (nsplit ...)
>
> when you don't want empty elements.
That's not entirely true when keep_empty is used in combination with
count. When keep_empty is false then the split is not considered a
(successful) split and internal state of count is not decreased.
Example:
# List.filter ((<>) "") (nsplit ~count:3 ","
"a,,,b,,,c,,d" ) ;;
- : string list = ["a"; "b,,,c,,d"]
# nsplit ~keep_empty:false ~count:3 "," "a,,,b,,,c,,d" ;;
- : string list = ["a"; "b"; "c"; ",d"]
IMHO that shows how ?keep_empty is a very complex interface that's
difficult for ordinary programmers to understand.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW