/
NonEmptyString.scala
1606 lines (1454 loc) · 82.9 KB
/
NonEmptyString.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalactic.anyvals
import scala.annotation.unchecked.{ uncheckedVariance => uV }
import scala.collection.GenIterable
import scala.collection.GenSeq
import scala.collection.GenTraversableOnce
import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.Buffer
import scala.reflect.ClassTag
import scala.collection.immutable
import scala.collection.mutable.ArrayBuffer
import org.scalactic.Every
import org.scalactic.Resources
// Can't be a LinearSeq[T] because Builder would be able to create an empty one.
/**
* A non-empty list: an ordered, immutable, non-empty collection of elements with <code>LinearSeq</code> performance characteristics.
*
* <p>
* The purpose of <code>NonEmptyString</code> is to allow you to express in a type that a <code>String</code> is non-empty, thereby eliminating the
* need for (and potential exception from) a run-time check for non-emptiness. For a non-empty sequence with <code>IndexedSeq</code>
* performance, see <a href="Every.html"><code>Every</code></a>.
* </p>
*
* <h2>Constructing <code>NonEmptyString</code>s</h2>
*
* <p>
* You can construct a <code>NonEmptyString</code> by passing one or more elements to the <code>NonEmptyString.apply</code> factory method:
* </p>
*
* <pre class="stHighlighted">
* scala> <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* res0: <span class="stType">org.scalactic.anyvals.NonEmptyString[Int]</span> = <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* Alternatively you can <em>cons</em> elements onto the <code>End</code> singleton object, similar to making a <code>String</code> starting with <code>Nil</code>:
* </p>
*
* <pre class="stHighlighted">
* scala> <span class="stLiteral">1</span> :: <span class="stLiteral">2</span> :: <span class="stLiteral">3</span> :: <span class="stType">Nil</span>
* res0: <span class="stType">String[Int]</span> = <span class="stType">String</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* <br/>scala> <span class="stLiteral">1</span> :: <span class="stLiteral">2</span> :: <span class="stLiteral">3</span> :: <span class="stType">End</span>
* res1: <span class="stType">org.scalactic.NonEmptyString[Int]</span> = <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* Note that although <code>Nil</code> is a <code>String[Nothing]</code>, <code>End</code> is
* not a <code>NonEmptyString[Nothing]</code>, because no empty <code>NonEmptyString</code> exists. (A non-empty list is a series
* of connected links; if you have no links, you have no non-empty list.)
* </p>
*
* <pre class="stHighlighted">
* scala> <span class="stReserved">val</span> nil: <span class="stType">String[Nothing]</span> = <span class="stType">Nil</span>
* nil: <span class="stType">String[Nothing]</span> = <span class="stType">String</span>()
* <br/>scala> <span class="stReserved">val</span> nada: <span class="stType">NonEmptyString[Nothing]</span> = <span class="stType">End</span>
* <console>:<span class="stLiteral">16</span>: error: <span class="stReserved">type</span> mismatch;
* found : org.scalactic.anyvals.End.type
* required: <span class="stType">org.scalactic.anyvals.NonEmptyString[Nothing]</span>
* <span class="stReserved">val</span> nada: <span class="stType">NonEmptyString[Nothing]</span> = <span class="stType">End</span>
* ^
* </pre>
*
* <h2>Working with <code>NonEmptyString</code>s</h2>
*
* <p>
* <code>NonEmptyString</code> does not extend Scala's <code>Seq</code> or <code>Traversable</code> traits because these require that
* implementations may be empty. For example, if you invoke <code>tail</code> on a <code>Seq</code> that contains just one element,
* you'll get an empty <code>Seq</code>:
* </p>
*
* <pre class="stREPL">
* scala> String(1).tail
* res6: String[Int] = String()
* </pre>
*
* <p>
* On the other hand, many useful methods exist on <code>Seq</code> that when invoked on a non-empty <code>Seq</code> are guaranteed
* to not result in an empty <code>Seq</code>. For convenience, <code>NonEmptyString</code> defines a method corresponding to every such <code>Seq</code>
* method. Here are some examples:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).map(_ + <span class="stLiteral">1</span>) <span class="stLineComment">// Result: NonEmptyString(2, 3, 4)</span>
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>).map(_ + <span class="stLiteral">1</span>) <span class="stLineComment">// Result: NonEmptyString(2)</span>
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).containsSlice(<span class="stType">NonEmptyString</span>(<span class="stLiteral">2</span>, <span class="stLiteral">3</span>)) <span class="stLineComment">// Result: true</span>
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).containsSlice(<span class="stType">NonEmptyString</span>(<span class="stLiteral">3</span>, <span class="stLiteral">4</span>)) <span class="stLineComment">// Result: false</span>
* <span class="stType">NonEmptyString</span>(-<span class="stLiteral">1</span>, -<span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>).minBy(_.abs) <span class="stLineComment">// Result: -1</span>
* </pre>
*
* <p>
* <code>NonEmptyString</code> does <em>not</em> currently define any methods corresponding to <code>Seq</code> methods that could result in
* an empty <code>Seq</code>. However, an implicit converison from <code>NonEmptyString</code> to <code>String</code>
* is defined in the <code>NonEmptyString</code> companion object that will be applied if you attempt to call one of the missing methods. As a
* result, you can invoke <code>filter</code> on an <code>NonEmptyString</code>, even though <code>filter</code> could result
* in an empty sequence—but the result type will be <code>String</code> instead of <code>NonEmptyString</code>:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).filter(_ < <span class="stLiteral">10</span>) <span class="stLineComment">// Result: String(1, 2, 3)</span>
* <span class="stType">NonEmptyString</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).filter(_ > <span class="stLiteral">10</span>) <span class="stLineComment">// Result: String()</span>
* </pre>
*
*
* <p>
* You can use <code>NonEmptyString</code>s in <code>for</code> expressions. The result will be an <code>NonEmptyString</code> unless
* you use a filter (an <code>if</code> clause). Because filters are desugared to invocations of <code>filter</code>, the
* result type will switch to a <code>String</code> at that point. Here are some examples:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalactic.anyvals._
* import org.scalactic.anyvals._
*
* scala> for (i <- NonEmptyString(1, 2, 3)) yield i + 1
* res0: org.scalactic.anyvals.NonEmptyString[Int] = NonEmptyString(2, 3, 4)
*
* scala> for (i <- NonEmptyString(1, 2, 3) if i < 10) yield i + 1
* res1: String[Int] = String(2, 3, 4)
*
* scala> for {
* | i <- NonEmptyString(1, 2, 3)
* | j <- NonEmptyString('a', 'b', 'c')
* | } yield (i, j)
* res3: org.scalactic.anyvals.NonEmptyString[(Int, Char)] =
* NonEmptyString((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))
*
* scala> for {
* | i <- NonEmptyString(1, 2, 3) if i < 10
* | j <- NonEmptyString('a', 'b', 'c')
* | } yield (i, j)
* res6: String[(Int, Char)] =
* String((1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c))
* </pre>
*
*/
final class NonEmptyString private (val theString: String) extends AnyVal {
/**
* Returns a new <code>NonEmptyString</code> containing this <code>NonEmptyString</code> followed by the passed <code>NonEmptyString</code>.
*
* @param other the <code>NonEmptyString</code> to append
* @return a new <code>NonEmptyString</code> that contains this <code>NonEmptyString</code> followed by <code>other</code>.
*/
def ++(other: NonEmptyString): NonEmptyString = new NonEmptyString(theString ++ other.theString)
/**
* Returns a new <code>NonEmptyString</code> containing this <code>NonEmptyString</code> followed by the characters of the passed <code>Every</code>.
*
* @param other the <code>Every</code> of <code>Char</code> to append
* @return a new <code>NonEmptyString</code> that contains this <code>NonEmptyString</code> followed by all characters of <code>other</code>.
*/
def ++(other: Every[Char]): NonEmptyString = new NonEmptyString(theString ++ other.mkString)
// TODO: Have I added these extra ++, etc. methods to Every that take a NonEmptyString?
/**
* Returns a new <code>NonEmptyString</code> containing this <code>NonEmptyString</code> followed by the characters of the passed <code>GenTraversableOnce</code>.
*
* @param other the <code>GenTraversableOnce</code> of <code>Char</code> to append
* @return a new <code>NonEmptyString</code> that contains this <code>NonEmptyString</code> followed by all characters of <code>other</code>.
*/
def ++(other: GenTraversableOnce[Char]): NonEmptyString =
if (other.isEmpty) this else new NonEmptyString(theString ++ other.mkString)
/**
* Returns a new <code>NonEmptyString</code> with the given character prepended.
*
* <p>
* Note that :-ending operators are right associative. A mnemonic for <code>+:</code> <em>vs.</em> <code>:+</code> is: the COLon goes on the COLlection side.
* </p>
*
* @param c the character to prepend to this <code>NonEmptyString</code>
* @return a new <code>NonEmptyString</code> consisting of <code>c</code> followed by all characters of this <code>NonEmptyString</code>.
*/
final def +:(c: Char): NonEmptyString = new NonEmptyString(c +: theString)
/**
* Returns a new <code>NonEmptyString</code> with the given character appended.
*
* <p>
* Note a mnemonic for <code>+:</code> <em>vs.</em> <code>:+</code> is: the COLon goes on the COLlection side.
* </p>
*
* @param c the character to append to this <code>NonEmptyString</code>
* @return a new <code>NonEmptyString</code> consisting of all characters of this <code>NonEmptyString</code> followed by the given <code>c</code>.
*/
def :+(c: Char): NonEmptyString = new NonEmptyString(theString :+ c)
/**
* Appends all characters of this <code>NonEmptyString</code> to a string builder. The written text will consist of a concatenation of the result of invoking <code>toString</code>
* on of every element of this <code>NonEmptyString</code>, without any separator string.
*
* @param sb the string builder to which characters will be appended
* @return the string builder, <code>sb</code>, to which elements were appended.
*/
final def addString(sb: StringBuilder): StringBuilder = theString.addString(sb)
/**
* Appends all characters of this <code>NonEmptyString</code> to a string builder using a separator string. The written text will consist of a concatenation of the
* result of invoking <code>toString</code>
* on of every character of this <code>NonEmptyString</code>, separated by the string <code>sep</code>.
*
* @param sb the string builder to which characters will be appended
* @param sep the separator string
* @return the string builder, <code>sb</code>, to which characters were appended.
*/
final def addString(sb: StringBuilder, sep: String): StringBuilder = theString.addString(sb, sep)
/**
* Appends all characters of this <code>NonEmptyString</code> to a string builder using start, end, and separator strings. The written text will consist of a concatenation of
* the string <code>start</code>; the result of invoking <code>toString</code> on all characters of this <code>NonEmptyString</code>,
* separated by the string <code>sep</code>; and the string <code>end</code>
*
* @param sb the string builder to which characters will be appended
* @param start the starting string
* @param sep the separator string
* @param end the ending string
* @return the string builder, <code>sb</code>, to which characters were appended.
*/
final def addString(sb: StringBuilder, start: String, sep: String, end: String): StringBuilder = theString.addString(sb, start, sep, end)
/**
* Selects a character by its index in the <code>NonEmptyString</code>.
*
* @return the character of this <code>NonEmptyString</code> at index <code>idx</code>, where 0 indicates the first element.
*/
final def apply(idx: Int): Char = theString(idx)
/**
* Gets a character by its index in the <code>NonEmptyString</code>.
*
* @return the character of this <code>NonEmptyString</code> at index <code>idx</code>, where 0 indicates the first element.
*/
final def charAt(idx: Int): Char = theString.charAt(idx)
/**
* Finds the first character of this <code>NonEmptyString</code> for which the given partial function is defined, if any, and applies the partial function to it.
*
* @param pf the partial function
* @return an <code>Option</code> containing <code>pf</code> applied to the first character for which it is defined, or <code>None</code> if
* the partial function was not defined for any character.
*/
final def collectFirst[U](pf: PartialFunction[Char, U]): Option[U] = theString.collectFirst(pf)
/**
* Indicates whether this <code>NonEmptyString</code> contains a given value as an character.
*
* @param c the element to look for
* @return true if this <code>NonEmptyString</code> has an character that is equal (as determined by <code>==)</code> to <code>c</code>, false otherwise.
*/
final def contains(c: Char): Boolean = theString.contains(c)
/**
* Indicates whether this <code>NonEmptyString</code> contains a given <code>GenSeq</code> of characters as a slice.
*
* @param that the <code>GenSeq</code> character slice to look for
* @return true if this <code>NonEmptyString</code> contains a slice with the same characters as <code>that</code>, otherwise <code>false</code>.
*/
final def containsSlice(that: GenSeq[Char]): Boolean = theString.containsSlice(that)
/**
* Indicates whether this <code>NonEmptyString</code> contains a given <code>Every</code> of character as a slice.
*
* @param that the <code>Every</code> character slice to look for
* @return true if this <code>NonEmptyString</code> contains a character slice with the same characters as <code>that</code>, otherwise <code>false</code>.
*/
final def containsSlice(that: Every[Char]): Boolean = theString.containsSlice(that.toVector)
/**
* Indicates whether this <code>NonEmptyString</code> contains a given <code>NonEmptyString</code> as a slice.
*
* @param that the <code>NonEmptyString</code> slice to look for
* @return true if this <code>NonEmptyString</code> contains a slice with the same characters as <code>that</code>, otherwise <code>false</code>.
*/
final def containsSlice(that: NonEmptyString): Boolean = theString.containsSlice(that.theString)
/**
* Copies characters of this <code>NonEmptyString</code> to an array. Fills the given array <code>arr</code> with characters of this <code>NonEmptyString</code>. Copying
* will stop once either the end of the current <code>NonEmptyString</code> is reached, or the end of the array is reached.
*
* @param arr the array to fill
*/
final def copyToArray(arr: Array[Char]): Unit = theString.copyToArray(arr, 0)
/**
* Copies characters of this <code>NonEmptyString</code> to an array. Fills the given array <code>arr</code> with characters of this <code>NonEmptyString</code>, beginning at
* index <code>start</code>. Copying will stop once either the end of the current <code>NonEmptyString</code> is reached, or the end of the array is reached.
*
* @param arr the array to fill
* @param start the starting index
*/
final def copyToArray(arr: Array[Char], start: Int): Unit = theString.copyToArray(arr, start)
/**
* Copies characters of this <code>NonEmptyString</code> to an array. Fills the given array <code>arr</code> with at most <code>len</code> characters of this <code>NonEmptyString</code>, beginning at
* index <code>start</code>. Copying will stop once either the end of the current <code>NonEmptyString</code> is reached, the end of the array is reached, or
* <code>len</code> elements have been copied.
*
* @param arr the array to fill
* @param start the starting index
* @param len the maximum number of elements to copy
*/
final def copyToArray(arr: Array[Char], start: Int, len: Int): Unit = theString.copyToArray(arr, start, len)
/**
* Copies all characters of this <code>NonEmptyString</code> to a buffer.
*
* @param buf the buffer to which characters are copied
*/
final def copyToBuffer(buf: Buffer[Char]): Unit = theString.copyToBuffer(buf)
/**
* Indicates whether every character of this <code>NonEmptyString</code> relates to the corresponding element of a given <code>GenSeq</code> by satisfying a given predicate.
*
* @tparam B the type of the elements of <code>that</code>
* @param that the <code>GenSeq</code> to compare for correspondence
* @param p the predicate, which relates elements from this <code>NonEmptyString</code> and the passed <code>GenSeq</code>
* @return true if this <code>NonEmptyString</code> and the passed <code>GenSeq</code> have the same length and <code>p(x, y)</code> is <code>true</code>
* for all corresponding elements <code>x</code> of this <code>NonEmptyString</code> and <code>y</code> of that, otherwise <code>false</code>.
*/
final def corresponds[B](that: GenSeq[B])(p: (Char, B) => Boolean): Boolean = theString.corresponds(that)(p)
/**
* Indicates whether every character of this <code>NonEmptyString</code> relates to the corresponding element of a given <code>Every</code> by satisfying a given predicate.
*
* @tparam B the type of the elements of <code>that</code>
* @param that the <code>Every</code> to compare for correspondence
* @param p the predicate, which relates elements from this <code>NonEmptyString</code> and the passed <code>Every</code>
* @return true if this <code>NonEmptyString</code> and the passed <code>Every</code> have the same length and <code>p(x, y)</code> is <code>true</code>
* for all corresponding elements <code>x</code> of this <code>NonEmptyString</code> and <code>y</code> of that, otherwise <code>false</code>.
*/
final def corresponds[B](that: Every[B])(p: (Char, B) => Boolean): Boolean = theString.corresponds(that.toVector)(p)
/**
* Indicates whether every character of this <code>NonEmptyString</code> relates to the corresponding character of a given <code>NonEmptyString</code> by satisfying a given predicate.
*
* @param that the <code>NonEmptyString</code> to compare for correspondence
* @param p the predicate, which relates elements from this and the passed <code>NonEmptyString</code>
* @return true if this and the passed <code>NonEmptyString</code> have the same length and <code>p(x, y)</code> is <code>true</code>
* for all corresponding characters <code>x</code> of this <code>NonEmptyString</code> and <code>y</code> of that, otherwise <code>false</code>.
*/
final def corresponds(that: NonEmptyString)(p: (Char, Char) => Boolean): Boolean = theString.corresponds(that.theString)(p)
/**
* Counts the number of characters in this <code>NonEmptyString</code> that satisfy a predicate.
*
* @param p the predicate used to test characters.
* @return the number of characters satisfying the predicate <code>p</code>.
*/
final def count(p: Char => Boolean): Int = theString.count(p)
/**
* Builds a new <code>NonEmptyString</code> from this <code>NonEmptyString</code> without any duplicate characters.
*
* @return A new <code>NonEmptyString</code> that contains the first occurrence of every character of this <code>NonEmptyString</code>.
*/
final def distinct: NonEmptyString = new NonEmptyString(theString.distinct)
/**
* Indicates whether this <code>NonEmptyString</code> ends with the given <code>GenSeq</code> of Char.
*
* @param that the sequence to test
* @return <code>true</code> if this <code>NonEmptyString</code> has <code>that</code> as a suffix, <code>false</code> otherwise.
*/
final def endsWith[B](that: GenSeq[B]): Boolean = theString.endsWith(that)
/**
* Indicates whether this <code>NonEmptyString</code> ends with the given <code>Every</code>.
*
* @param that the <code>Every</code> to test
* @return <code>true</code> if this <code>NonEmptyString</code> has <code>that</code> as a suffix, <code>false</code> otherwise.
*/
final def endsWith[B](that: Every[B]): Boolean = theString.endsWith(that.toVector)
// TODO: Search for that: Every in here and add a that: NonEmptyString in Every.
/**
* Indicates whether this <code>NonEmptyString</code> ends with the given <code>NonEmptyString</code>.
*
* @param that the <code>NonEmptyString</code> to test
* @return <code>true</code> if this <code>NonEmptyString</code> has <code>that</code> as a suffix, <code>false</code> otherwise.
*/
final def endsWith(that: NonEmptyString): Boolean = theString.endsWith(that.theString)
/*
override def equals(o: Any): Boolean =
o match {
case nonEmptyString: NonEmptyString[_] => toString == nonEmptyString.toString
case _ => false
}
*/
/**
* Indicates whether a predicate holds for at least one of the characters of this <code>NonEmptyString</code>.
*
* @param p the predicate used to test characters.
* @return <code>true</code> if the given predicate <code>p</code> holds for some of the elements of this <code>NonEmptyString</code>, otherwise <code>false</code>.
*/
final def exists(p: Char => Boolean): Boolean = theString.exists(p)
/**
* Finds the first character of this <code>NonEmptyString</code> that satisfies the given predicate, if any.
*
* @param p the predicate used to test characters
* @return an <code>Some</code> containing the first character in this <code>NonEmptyString</code> that satisfies <code>p</code>, or <code>None</code> if none exists.
*/
final def find(p: Char => Boolean): Option[Char] = theString.find(p)
/**
* Builds a new <code>NonEmptyString</code> by applying a function to all characters of this <code>NonEmptyString</code> and using the characters of the resulting <code>NonEmptyString</code>s.
*
* @param f the function to apply to each character.
* @return a new <code>NonEmptyString</code> containing characters obtained by applying the given function <code>f</code> to each character of this <code>NonEmptyString</code> and concatenating
* the characters of resulting <code>NonEmptyString</code>s.
*/
final def flatMap(f: Char => NonEmptyString): NonEmptyString = {
val buf = new ArrayBuffer[Char]
for (c <- theString)
buf ++= f(c).theString
new NonEmptyString(buf.mkString)
}
/**
* Folds the characters of this <code>NonEmptyString</code> using the specified associative binary operator.
*
* <p>
* The order in which operations are performed on characters is unspecified and may be nondeterministic.
* </p>
*
* @param z a neutral character for the fold operation; may be added to the result an arbitrary number of
* times, and must not change the result (<em>e.g.</em>, <code>Nil</code> for list concatenation,
* 0 for addition, or 1 for multiplication.)
* @param op a binary operator that must be associative
* @return the result of applying fold operator <code>op</code> between all the elements and <code>z</code>
*/
final def fold(z: Char)(op: (Char, Char) => Char): Char = theString.fold(z)(op)
/**
* Applies a binary operator to a start value and all characters of this <code>NonEmptyString</code>, going left to right.
*
* @tparam B the result type of the binary operator.
* @param z the start value.
* @param op the binary operator.
* @return the result of inserting <code>op</code> between consecutive characters of this <code>NonEmptyString</code>, going left to right, with the start value,
* <code>z</code>, on the left:
*
* <pre>
* op(...op(op(z, x_1), x_2), ..., x_n)
* </pre>
*
* <p>
* where x<sub>1</sub>, ..., x<sub>n</sub> are the elements of this <code>NonEmptyString</code>.
* </p>
*/
final def foldLeft[B](z: B)(op: (B, Char) => B): B = theString.foldLeft(z)(op)
/**
* Applies a binary operator to all characters of this <code>NonEmptyString</code> and a start value, going right to left.
*
* @tparam B the result of the binary operator
* @param z the start value
* @param op the binary operator
* @return the result of inserting <code>op</code> between consecutive characters of this <code>NonEmptyString</code>, going right to left, with the start value,
* <code>z</code>, on the right:
*
* <pre>
* op(x_1, op(x_2, ... op(x_n, z)...))
* </pre>
*
* <p>
* where x<sub>1</sub>, ..., x<sub>n</sub> are the elements of this <code>NonEmptyString</code>.
* </p>
*/
final def foldRight[B](z: B)(op: (Char, B) => B): B = theString.foldRight(z)(op)
/**
* Indicates whether a predicate holds for all characters of this <code>NonEmptyString</code>.
*
* @param p the predicate used to test characters.
* @return <code>true</code> if the given predicate <code>p</code> holds for all characters of this <code>NonEmptyString</code>, otherwise <code>false</code>.
*/
final def forall(p: Char => Boolean): Boolean = theString.forall(p)
/**
* Applies a function <code>f</code> to all characters of this <code>NonEmptyString</code>.
*
* @param f the function that is applied for its side-effect to every character. The result of function <code>f</code> is discarded.
*/
final def foreach(f: Char => Unit): Unit = theString.foreach(f)
/**
* Partitions this <code>NonEmptyString</code> into a map of <code>NonEmptyString</code>s according to some discriminator function.
*
* @tparam K the type of keys returned by the discriminator function.
* @param f the discriminator function.
* @return A map from keys to <code>NonEmptyString</code>s such that the following invariant holds:
*
* <pre>
* (nonEmptyString.toString partition f)(k) = xs filter (x => f(x) == k)
* </pre>
*
* <p>
* That is, every key <code>k</code> is bound to a <code>NonEmptyString</code> of those elements <code>x</code> for which <code>f(x)</code> equals <code>k</code>.
* </p>
*/
final def groupBy[K](f: Char => K): Map[K, NonEmptyString] = {
val mapKToString = theString.groupBy(f)
mapKToString.mapValues { list => new NonEmptyString(list) }.toMap
}
/**
* Partitions characters into fixed size <code>NonEmptyString</code>s.
*
* @param size the number of characters per group
* @return An iterator producing <code>NonEmptyString</code>s of size <code>size</code>, except the last will be truncated if the characters don't divide evenly.
*/
final def grouped(size: Int): Iterator[NonEmptyString] = {
if (size > 0) {
val itOfString = theString.grouped(size)
itOfString.map { list => new NonEmptyString(list) }
}
else
throw new IllegalArgumentException(Resources.invalidSize(size))
}
/**
* Returns <code>true</code> to indicate this <code>NonEmptyString</code> has a definite size, since all <code>NonEmptyString</code>s are strict collections.
*/
final def hasDefiniteSize: Boolean = true
// override def hashCode: Int = toString.hashCode
/**
* Selects the first character of this <code>NonEmptyString</code>.
*
* @return the first character of this <code>NonEmptyString</code>.
*/
final def head: Char = theString.head
// Methods like headOption I can't get rid of because of the implicit conversion to GenTraversable.
// Users can call any of the methods I've left out on a NonEmptyString, and get whatever String would return
// for that method call. Eventually I'll probably implement them all to save the implicit conversion.
/**
* Selects the first character of this <code>NonEmptyString</code> and returns it wrapped in a <code>Some</code>.
*
* @return the first character of this <code>NonEmptyString</code>, wrapped in a <code>Some</code>.
*/
final def headOption: Option[Char] = theString.headOption
/**
* Finds index of first occurrence of some value in this <code>NonEmptyString</code>.
*
* @param c the character value to search for.
* @return the index of the first character of this <code>NonEmptyString</code> that is equal (as determined by <code>==</code>) to <code>c</code>,
* or <code>-1</code>, if none exists.
*/
final def indexOf(c: Char): Int = theString.indexOf(c, 0)
/**
* Finds index of first occurrence of some value in this <code>NonEmptyString</code> after or at some start index.
*
* @param c the character value to search for.
* @param from the start index
* @return the index <code>>=</code> <code>from</code> of the first element of this <code>NonEmptyString</code> that is equal (as determined by <code>==</code>) to <code>elem</code>,
* or <code>-1</code>, if none exists.
*/
final def indexOf(c: Char, from: Int): Int = theString.indexOf(c, from)
/**
* Finds first index where this <code>NonEmptyString</code> contains a given <code>GenSeq[Char]</code> as a slice.
*
* @param that the <code>GenSeq[Char]</code> defining the slice to look for
* @return the first index at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>GenSeq</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: GenSeq[Char]): Int = theString.indexOfSlice(that)
/**
* Finds first index after or at a start index where this <code>NonEmptyString</code> contains a given <code>GenSeq[Char]</code> as a slice.
*
* @param that the <code>GenSeq[Char]</code> defining the slice to look for
* @param from the start index
* @return the first index <code>>=</code> <code>from</code> at which the characters of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>GenSeq[Char]</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: GenSeq[Char], from: Int): Int = theString.indexOfSlice(that, from)
/**
* Finds first index where this <code>NonEmptyString</code> contains a given <code>Every</code> as a slice.
*
* @param that the <code>Every</code> defining the slice to look for
* @return the first index such that the characters of this <code>NonEmptyString</code> starting at this index match the characters of
* <code>Every</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: Every[Char]): Int = theString.indexOfSlice(that.toVector)
/**
* Finds first index where this <code>NonEmptyString</code> contains a given <code>NonEmptyString</code> as a slice.
*
* @param that the <code>NonEmptyString</code> defining the slice to look for
* @return the first index such that the characters of this <code>NonEmptyString</code> starting at this index match the characters of
* <code>NonEmptyString</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: NonEmptyString): Int = theString.indexOfSlice(that.theString)
/**
* Finds first index after or at a start index where this <code>NonEmptyString</code> contains a given <code>Every</code> as a slice.
*
* @param that the <code>Every</code> defining the slice to look for
* @param from the start index
* @return the first index <code>>=</code> <code>from</code> such that the characters of this <code>NonEmptyString</code> starting at this index match the characters of
* <code>Every</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: Every[Char], from: Int): Int = theString.indexOfSlice(that.toVector, from)
/**
* Finds first index after or at a start index where this <code>NonEmptyString</code> contains a given <code>NonEmptyString</code> as a slice.
*
* @param that the <code>NonEmptyString</code> defining the slice to look for
* @param from the start index
* @return the first index <code>>=</code> <code>from</code> such that the characters of this <code>NonEmptyString</code> starting at this index match the characters of
* <code>NonEmptyString</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def indexOfSlice(that: NonEmptyString, from: Int): Int = theString.indexOfSlice(that.theString, from)
/**
* Finds index of the first character satisfying some predicate.
*
* @param p the predicate used to test characters.
* @return the index of the first character of this <code>NonEmptyString</code> that satisfies the predicate <code>p</code>,
* or <code>-1</code>, if none exists.
*/
final def indexWhere(p: Char => Boolean): Int = theString.indexWhere(p)
/**
* Finds index of the first character satisfying some predicate after or at some start index.
*
* @param p the predicate used to test characters.
* @param from the start index
* @return the index <code>>=</code> <code>from</code> of the first character of this <code>NonEmptyString</code> that satisfies the predicate <code>p</code>,
* or <code>-1</code>, if none exists.
*/
final def indexWhere(p: Char => Boolean, from: Int): Int = theString.indexWhere(p, from)
/**
* Produces the range of all indices of this <code>NonEmptyString</code>.
*
* @return a <code>Range</code> value from <code>0</code> to one less than the length of this <code>NonEmptyString</code>.
*/
final def indices: Range = theString.indices
/**
* Tests whether this <code>NonEmptyString</code> contains given index.
*
* @param idx the index to test
* @return true if this <code>NonEmptyString</code> contains an character at position <code>idx</code>, <code>false</code> otherwise.
*/
final def isDefinedAt(idx: Int): Boolean = theString.isDefinedAt(idx)
/**
* Returns <code>false</code> to indicate this <code>NonEmptyString</code>, like all <code>NonEmptyString</code>s, is non-empty.
*
* @return false
*/
final def isEmpty: Boolean = false
/**
* Returns <code>true</code> to indicate this <code>NonEmptyString</code>, like all <code>NonEmptyString</code>s, can be traversed repeatedly.
*
* @return true
*/
final def isTraversableAgain: Boolean = true
/**
* Creates and returns a new iterator over all characters contained in this <code>NonEmptyString</code>.
*
* @return the new iterator
*/
final def iterator: Iterator[Char] = theString.iterator
/**
* Selects the last character of this <code>NonEmptyString</code>.
*
* @return the last character of this <code>NonEmptyString</code>.
*/
final def last: Char = theString.last
/**
* Finds the index of the last occurrence of some value in this <code>NonEmptyString</code>.
*
* @param c the character value to search for.
* @return the index of the last character of this <code>NonEmptyString</code> that is equal (as determined by <code>==</code>) to <code>c</code>,
* or <code>-1</code>, if none exists.
*/
final def lastIndexOf(c: Char): Int = theString.lastIndexOf(c)
/**
* Finds the index of the last occurrence of some value in this <code>NonEmptyString</code> before or at a given <code>end</code> index.
*
* @param c the character value to search for.
* @param end the end index.
* @return the index <code>>=</code> <code>end</code> of the last character of this <code>NonEmptyString</code> that is equal (as determined by <code>==</code>)
* to <code>elem</code>, or <code>-1</code>, if none exists.
*/
final def lastIndexOf(c: Char, end: Int): Int = theString.lastIndexOf(c, end)
/**
* Finds the last index where this <code>NonEmptyString</code> contains a given <code>GenSeq</code> as a slice.
*
* @param that the <code>GenSeq</code> defining the slice to look for
* @return the last index at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>GenSeq</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: GenSeq[Char]): Int = theString.lastIndexOfSlice(that)
/**
* Finds the last index before or at a given end index where this <code>NonEmptyString</code> contains a given <code>GenSeq</code> as a slice.
*
* @param that the <code>GenSeq</code> defining the slice to look for
* @param end the end index
* @return the last index <code>>=</code> <code>end</code> at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>GenSeq</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: GenSeq[Char], end: Int): Int = theString.lastIndexOfSlice(that, end)
/**
* Finds the last index where this <code>NonEmptyString</code> contains a given <code>Every</code> as a slice.
*
* @param that the <code>Every</code> defining the slice to look for
* @return the last index at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>Every</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: Every[Char]): Int = theString.lastIndexOfSlice(that.toVector)
/**
* Finds the last index where this <code>NonEmptyString</code> contains a given <code>NonEmptyString</code> as a slice.
*
* @param that the <code>NonEmptyString</code> defining the slice to look for
* @return the last index at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>NonEmptyString</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: NonEmptyString): Int = theString.lastIndexOfSlice(that.theString)
/**
* Finds the last index before or at a given end index where this <code>NonEmptyString</code> contains a given <code>Every</code> as a slice.
*
* @param that the <code>Every</code> defining the slice to look for
* @param end the end index
* @return the last index <code>>=</code> <code>end</code> at which the elements of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>Every</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: Every[Char], end: Int): Int = theString.lastIndexOfSlice(that.toVector, end)
/**
* Finds the last index before or at a given end index where this <code>NonEmptyString</code> contains a given <code>NonEmptyString</code> as a slice.
*
* @param that the <code>NonEmptyString</code> defining the slice to look for
* @param end the end index
* @return the last index <code>>=</code> <code>end</code> at which the characters of this <code>NonEmptyString</code> starting at that index match the characters of
* <code>NonEmptyString</code> <code>that</code>, or <code>-1</code> of no such subsequence exists.
*/
final def lastIndexOfSlice(that: NonEmptyString, end: Int): Int = theString.lastIndexOfSlice(that.theString, end)
/**
* Finds index of last character satisfying some predicate.
*
* @param p the predicate used to test characters.
* @return the index of the last character of this <code>NonEmptyString</code> that satisfies the predicate <code>p</code>, or <code>-1</code>, if none exists.
*/
final def lastIndexWhere(p: Char => Boolean): Int = theString.lastIndexWhere(p)
/**
* Finds index of last character satisfying some predicate before or at given end index.
*
* @param p the predicate used to test characters.
* @param end the end index
* @return the index <code>>=</code> <code>end</code> of the last character of this <code>NonEmptyString</code> that satisfies the predicate <code>p</code>,
* or <code>-1</code>, if none exists.
*/
final def lastIndexWhere(p: Char => Boolean, end: Int): Int = theString.lastIndexWhere(p, end)
/**
* Returns the last element of this <code>NonEmptyString</code>, wrapped in a <code>Some</code>.
*
* @return the last element, wrapped in a <code>Some</code>.
*/
final def lastOption: Option[Char] = theString.lastOption // Will always return a Some
/**
* The length of this <code>NonEmptyString</code>.
*
* <p>
* Note: <code>length</code> and <code>size</code> yield the same result, which will be <code>></code>= 1.
* </p>
*
* @return the number of characters in this <code>NonEmptyString</code>.
*/
final def length: Int = theString.length
/**
* Compares the length of this <code>NonEmptyString</code> to a test value.
*
* @param len the test value that gets compared with the length.
* @return a value <code>x</code> where
*
* <pre>
* x < 0 if this.length < len
* x == 0 if this.length == len
* x > 0 if this.length > len
* </pre>
*/
final def lengthCompare(len: Int): Int = theString.lengthCompare(len)
/**
* Builds a new <code>NonEmptyString</code> by applying a function to all characters of this <code>NonEmptyString</code>.
*
* @tparam U the character type of the returned <code>NonEmptyString</code>.
* @param f the function to apply to each character.
* @return a new <code>NonEmptyString</code> resulting from applying the given function <code>f</code> to each character of this <code>NonEmptyString</code> and collecting the results.
*/
final def map[U](f: Char => U): NonEmptyString = {
//NonEmptyString("test")
new NonEmptyString(
theString.map { c =>
f(c).toString
}.mkString
)
}
/**
* Finds the largest character.
*
* @return the largest element of this <code>NonEmptyString</code>.
*/
final def max(implicit cmp: Ordering[Char]): Char = theString.max(cmp)
/**
* Finds the largest result after applying the given function to every character.
*
* @return the largest result of applying the given function to every character of this <code>NonEmptyString</code>.
*/
final def maxBy[U](f: Char => U)(implicit cmp: Ordering[U]): Char = theString.maxBy(f)(cmp)
/**
* Finds the smallest character.
*
* @return the smallest character of this <code>NonEmptyString</code>.
*/
final def min(implicit cmp: Ordering[Char]): Char = theString.min(cmp)
/**
* Finds the smallest result after applying the given function to every character.
*
* @return the smallest result of applying the given function to every character of this <code>NonEmptyString</code>.
*/
final def minBy[U](f: Char => U)(implicit cmp: Ordering[U]): Char = theString.minBy(f)(cmp)
/**
* Displays all characters of this <code>NonEmptyString</code> in a string.
*
* @return a string representation of this <code>NonEmptyString</code>. In the resulting string, the result of invoking <code>toString</code> on all characters of this
* <code>NonEmptyString</code> follow each other without any separator string.
*/
final def mkString: String = theString.mkString
/**
* Displays all elements of this <code>NonEmptyString</code> in a string using a separator string.
*
* @param sep the separator string
* @return a string representation of this <code>NonEmptyString</code>. In the resulting string, the result of invoking <code>toString</code> on all elements of this
* <code>NonEmptyString</code> are separated by the string <code>sep</code>.
*/
final def mkString(sep: String): String = theString.mkString(sep)
/**
* Displays all characters of this <code>NonEmptyString</code> in a string using start, end, and separator strings.
*
* @param start the starting string.
* @param sep the separator string.
* @param end the ending string.
* @return a string representation of this <code>NonEmptyString</code>. The resulting string begins with the string <code>start</code> and ends with the string
* <code>end</code>. Inside, In the resulting string, the result of invoking <code>toString</code> on all characters of this <code>NonEmptyString</code> are
* separated by the string <code>sep</code>.
*/
final def mkString(start: String, sep: String, end: String): String = theString.mkString(start, sep, end)
/**
* Returns <code>true</code> to indicate this <code>NonEmptyString</code>, like all <code>NonEmptyString</code>s, is non-empty.
*
* @return true
*/
final def nonEmpty: Boolean = true
/**
* A copy of this <code>NonEmptyString</code> with an element value appended until a given target length is reached.
*
* @param len the target length
* @param c the padding character
* @return a new <code>NonEmptyString</code> consisting of all characters of this <code>NonEmptyString</code> followed by the minimal number of occurrences
* of <code>elem</code> so that the resulting <code>NonEmptyString</code> has a length of at least <code>len</code>.
*/
final def padTo(len: Int, c: Char): NonEmptyString =
new NonEmptyString(theString.padTo(len, c))
/**
* Produces a new <code>NonEmptyString</code> where a slice of characters in this <code>NonEmptyString</code> is replaced by another <code>NonEmptyString</code>
*
* @param from the index of the first replaced character
* @param that the <code>NonEmptyString</code> whose characters should replace a slice in this <code>NonEmptyString</code>
* @param replaced the number of characters to drop in the original <code>NonEmptyString</code>
*/
final def patch(from: Int, that: NonEmptyString, replaced: Int): NonEmptyString =
new NonEmptyString(theString.patch(from, that.theString, replaced))
/**
* Iterates over distinct permutations.
*
* <p>
* Here's an example:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">NonEmptyString</span>(<span class="stQuotedString">"abb"</span>).permutations.toList == list(<span class="stType">NonEmptyString</span>(<span class="stQuotedString">"abb"</span>), <span class="stType">NonEmptyString</span>(<span class="stQuotedString">"bab"</span>), <span class="stType">NonEmptyString</span>(<span class="stQuotedString">"bba"</span>))
* </pre>
*
* @return an iterator that traverses the distinct permutations of this <code>NonEmptyString</code>.
*/
final def permutations: Iterator[NonEmptyString] = {
val it = theString.permutations
it map { list => new NonEmptyString(list) }
}
/**
* Returns the length of the longest prefix whose characters all satisfy some predicate.
*
* @param p the predicate used to test characters.
* @return the length of the longest prefix of this <code>NonEmptyString</code> such that every characters
* of the segment satisfies the predicate <code>p</code>.
*/
final def prefixLength(p: Char => Boolean): Int = theString.prefixLength(p)
/**
* The result of multiplying all the characters of this <code>NonEmptyString</code>.
*
* <p>
* This method can be invoked for any <code>NonEmptyString</code> for which an implicit <code>Numeric[T]</code> exists.
* </p>
*
* @return the product of all elements
*/
final def product(implicit num: Numeric[Char]): Char = theString.product(num)
/**
* Reduces the elements of this <code>NonEmptyString</code> using the specified associative binary operator.
*
* <p>
* The order in which operations are performed on characters is unspecified and may be nondeterministic.
* </p>
*
* @param op a binary operator that must be associative.
* @return the result of applying reduce operator <code>op</code> between all the characters of this <code>NonEmptyString</code>.
*/
final def reduce(op: (Char, Char) => Char): Char = theString.reduce(op)
/**
* Applies a binary operator to all characters of this <code>NonEmptyString</code>, going left to right.
*
* @param op the binary operator.
* @return the result of inserting <code>op</code> between consecutive characters of this <code>NonEmptyString</code>, going left to right:
*
* <pre>
* op(...op(op(x_1, x_2), x_3), ..., x_n)
* </pre>
*
* <p>
* where x<sub>1</sub>, ..., x<sub>n</sub> are the characters of this <code>NonEmptyString</code>.
* </p>
*/
final def reduceLeft(op: (Char, Char) => Char): Char = theString.reduceLeft(op)
/**
* Applies a binary operator to all characters of this <code>NonEmptyString</code>, going left to right, returning the result in a <code>Some</code>.
*