@@ -179,8 +179,8 @@ class IMAP
179
179
# - #include_star?: Returns whether the set contains <tt>*</tt>.
180
180
#
181
181
# <i>Minimum and maximum value elements:</i>
182
- # - #min: Returns the minimum number in the set.
183
- # - #max: Returns the maximum number in the set.
182
+ # - #min: Returns one or more minimum numbers in the set.
183
+ # - #max: Returns one or more maximum numbers in the set.
184
184
# - #minmax: Returns the minimum and maximum numbers in the set.
185
185
#
186
186
# <i>Accessing value by offset in sorted set:</i>
@@ -567,26 +567,52 @@ def disjoint?(other)
567
567
empty? || input_to_tuples ( other ) . none? { intersect_tuple? _1 }
568
568
end
569
569
570
- # :call-seq: max(star: :*) => integer or star or nil
570
+ # :call-seq:
571
+ # max(star: :*) => integer or star or nil
572
+ # max(count, star: :*) => SequenceSet
571
573
#
572
574
# Returns the maximum value in +self+, +star+ when the set includes
573
575
# <tt>*</tt>, or +nil+ when the set is empty.
574
- def max ( star : :* )
575
- ( val = @tuples . last &.last ) && val == STAR_INT ? star : val
576
+ #
577
+ # When +count+ is given, a new SequenceSet is returned, containing only
578
+ # the last +count+ numbers. An empty SequenceSet is returned when +self+
579
+ # is empty. (+star+ is ignored when +count+ is given.)
580
+ #
581
+ # Related: #min, #minmax, #slice
582
+ def max ( count = nil , star : :* )
583
+ if count
584
+ slice ( -[ count , size ] . min ..) || remain_frozen_empty
585
+ elsif ( val = @tuples . last &.last )
586
+ val == STAR_INT ? star : val
587
+ end
576
588
end
577
589
578
- # :call-seq: min(star: :*) => integer or star or nil
590
+ # :call-seq:
591
+ # min(star: :*) => integer or star or nil
592
+ # min(count, star: :*) => SequenceSet
579
593
#
580
594
# Returns the minimum value in +self+, +star+ when the only value in the
581
595
# set is <tt>*</tt>, or +nil+ when the set is empty.
582
- def min ( star : :* )
583
- ( val = @tuples . first &.first ) && val == STAR_INT ? star : val
596
+ #
597
+ # When +count+ is given, a new SequenceSet is returned, containing only
598
+ # the first +count+ numbers. An empty SequenceSet is returned when +self+
599
+ # is empty. (+star+ is ignored when +count+ is given.)
600
+ #
601
+ # Related: #max, #minmax, #slice
602
+ def min ( count = nil , star : :* )
603
+ if count
604
+ slice ( 0 ...count ) || remain_frozen_empty
605
+ elsif ( val = @tuples . first &.first )
606
+ val != STAR_INT ? val : star
607
+ end
584
608
end
585
609
586
610
# :call-seq: minmax(star: :*) => nil or [integer, integer or star]
587
611
#
588
612
# Returns a 2-element array containing the minimum and maximum numbers in
589
613
# +self+, or +nil+ when the set is empty.
614
+ #
615
+ # Related: #min, #max
590
616
def minmax ( star : :* ) ; [ min ( star : star ) , max ( star : star ) ] unless empty? end
591
617
592
618
# Returns false when the set is empty.
@@ -1276,6 +1302,7 @@ def slice_range(range)
1276
1302
# Net::IMAP::SequenceSet["500:*"].limit(max: 37)
1277
1303
# #=> Net::IMAP::SequenceSet["37"]
1278
1304
#
1305
+ # Related: #limit!
1279
1306
def limit ( max :)
1280
1307
max = to_tuple_int ( max )
1281
1308
if empty? then self . class . empty
0 commit comments