title: How to find continuous segment pair in given list of integers (Functionally not imerative)?
body: <p>I have List of integers like {1,2,3,5,8,9,10}, I need the following result
  [1,3],[5,5],[8,10]</p>
  
  <p>I written the solution using imperative style, but I want a solution which align with functional programming.</p>
  
  <p>My imperative solution:</p>
  
  <pre><code>    public static List&lt;ContinuousNotificationSegment&gt; ConvertToNotificationSegment(this List&lt;NotificationDTO&gt; input)
      {
          var sortedNotificationList = input.Select(n =&gt; n.ID).ToList();
          sortedNotificationList = sortedNotificationList.OrderBy(n =&gt; n).ToList();
          List&lt;ContinuousNotificationSegment&gt; continuousSegments = new List&lt;ContinuousNotificationSegment&gt;();
  
          long continuousSegmentStart = 0, continuousSegmentEnd = 0;
  
          for (int i = 0; i &lt; sortedNotificationList.Count; i++)
          {                
              if (IsContinuous(sortedNotificationList[i], ((i + 1) &lt; sortedNotificationList.Count ? sortedNotificationList[i + 1] : -999)))
              {
                  continuousSegmentStart = continuousSegmentStart == 0 ? sortedNotificationList[i] : continuousSegmentStart;
              }
              else
              {
                  continuousSegmentEnd = sortedNotificationList[i];
  
                  continuousSegments.Add(new ContinuousNotificationSegment
                  {
                      MinNotificationId = continuousSegmentStart == 0 ? continuousSegmentEnd : continuousSegmentStart,
                      MaxNotificationId = continuousSegmentEnd
                  });
  
                  continuousSegmentStart = 0;
              }
          }
  
          return continuousSegments;
      }
  
      private static bool IsContinuous(long prevValue, long nextValue)
      {
          return nextValue - prevValue == 1;
      }
  </code></pre>