Documentation

Init.Data.String.Iterate

  • currPos : s.Pos
Instances For
    @[implicit_reducible]

    Creates an iterator over the valid positions within s, starting at p.

    Instances For

      Creates an iterator over all valid positions within {name}s.

      Examples:

      • {lean}("abc".toSlice.positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', 'c']
      • {lean}("abc".toSlice.positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2]
      • {lean}("ab∀c".toSlice.positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', '∀', 'c']
      • {lean}("ab∀c".toSlice.positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2, 5]
      Instances For
        @[implicit_reducible]
        @[inline]

        Creates an iterator over all characters (Unicode code points) in s.

        Examples:

        • "abc".toSlice.chars.toList = ['a', 'b', 'c']

        • "ab∀c".toSlice.chars.toList = ['a', 'b', '∀', 'c']

        Instances For
          @[deprecated "There is no constant-time length function on slices. Use `s.positions.length` instead, or `isEmpty` if you only need to know whether the slice is empty." (since := "2025-11-20")]
          Instances For
            • currPos : s.Pos
            Instances For

              Creates an iterator over all valid positions within s that are strictly smaller than p, starting from the position before p and iterating towards the first one.

              Instances For

                Creates an iterator over all valid positions within {name}s, starting from the last valid position and iterating towards the first one.

                Examples

                • {lean}("abc".toSlice.revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', 'b', 'a']
                • {lean}("abc".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [2, 1, 0]
                • {lean}("ab∀c".toSlice.revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', '∀', 'b', 'a']
                • {lean}("ab∀c".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [5, 2, 1, 0]
                Instances For
                  @[implicit_reducible]
                  @[inline]

                  Creates an iterator over all characters (Unicode code points) in s, starting from the end of the slice and iterating towards the start.

                  Example:

                  • "abc".toSlice.revChars.toList = ['c', 'b', 'a']

                  • "ab∀c".toSlice.revChars.toList = ['c', '∀', 'b', 'a']

                  Instances For
                    Instances For

                      Creates an iterator over all bytes in {name}s.

                      Examples:

                      • {lean}"abc".toSlice.bytes.toList = [97, 98, 99]
                      • {lean}"ab∀c".toSlice.bytes.toList = [97, 98, 226, 136, 128, 99]
                      Instances For
                        @[implicit_reducible]
                        Instances For

                          Creates an iterator over all bytes in {name}s, starting from the last one and iterating towards the first one.

                          Examples:

                          • {lean}"abc".toSlice.revBytes.toList = [99, 98, 97]
                          • {lean}"ab∀c".toSlice.revBytes.toList = [99, 128, 136, 226, 98, 97]
                          Instances For
                            @[implicit_reducible]
                            @[implicit_reducible]
                            @[inline]
                            def String.Slice.foldl {α : Type u} (f : αCharα) (init : α) (s : Slice) :
                            α

                            Folds a function over a slice from the start, accumulating a value starting with init. The accumulated value is combined with each character in order, using f.

                            Examples:

                            • "coffee tea water".toSlice.foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 2

                            • "coffee tea and water".toSlice.foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 3

                            • "coffee tea water".toSlice.foldl (·.push ·) "" = "coffee tea water"

                            Instances For
                              @[inline]
                              def String.Slice.foldr {α : Type u} (f : Charαα) (init : α) (s : Slice) :
                              α

                              Folds a function over a slice from the end, accumulating a value starting with init. The accumulated value is combined with each character in reverse order, using f.

                              Examples:

                              • "coffee tea water".toSlice.foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 2

                              • "coffee tea and water".toSlice.foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 3

                              • "coffee tea water".toSlice.foldr (fun c s => s.push c) "" = "retaw aet eeffoc"

                              Instances For
                                @[inline]
                                Instances For
                                  def String.positionsFrom (s : String) (p : s.Pos) :

                                  Creates an iterator over the valid positions within s, starting at p.

                                  Instances For
                                    @[inline]

                                    Creates an iterator over all valid positions within s.

                                    Examples

                                    • ("abc".positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', 'c']

                                    • ("abc".positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2]

                                    • ("ab∀c".positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', '∀', 'c']

                                    • ("ab∀c".positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2, 5]

                                    Instances For
                                      @[inline]

                                      Creates an iterator over all characters (Unicode code points) in s.

                                      Examples:

                                      • "abc".chars.toList = ['a', 'b', 'c']

                                      • "ab∀c".chars.toList = ['a', 'b', '∀', 'c']

                                      Instances For

                                        Creates an iterator over all valid positions within s that are strictly smaller than p, starting from the position before p and iterating towards the first one.

                                        Instances For
                                          @[inline]

                                          Creates an iterator over all valid positions within s, starting from the last valid position and iterating towards the first one.

                                          Examples

                                          • ("abc".revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', 'b', 'a']

                                          • ("abc".revPositions.map (·.val.offset.byteIdx) |>.toList) = [2, 1, 0]

                                          • ("ab∀c".revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', '∀', 'b', 'a']

                                          • ("ab∀c".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [5, 2, 1, 0]

                                          Instances For
                                            @[inline]

                                            Creates an iterator over all characters (Unicode code points) in s, starting from the end of the slice and iterating towards the start.

                                            Example:

                                            • "abc".revChars.toList = ['c', 'b', 'a']

                                            • "ab∀c".revChars.toList = ['c', '∀', 'b', 'a']

                                            Instances For
                                              @[inline]

                                              Creates an iterator over all bytes in s.

                                              Examples:

                                              • "abc".byteIterator.toList = [97, 98, 99]

                                              • "ab∀c".byteIterator.toList = [97, 98, 226, 136, 128, 99]

                                              Instances For
                                                @[inline]

                                                Creates an iterator over all bytes in s, starting from the last one and iterating towards the first one.

                                                Examples:

                                                • "abc".revBytes.toList = [99, 98, 97]

                                                • "ab∀c".revBytes.toList = [99, 128, 136, 226, 98, 97]

                                                Instances For
                                                  @[implicit_reducible]