dig

in lib/anthropic/internal/util.rb [182:203]


        def dig(data, pick, sentinel = nil, &blk)
          case [data, pick, blk]
          in [_, nil, nil]
            data
          in [Hash, Symbol, _] | [Array, Integer, _]
            blk.nil? ? data.fetch(pick, sentinel) : data.fetch(pick, &blk)
          in [Hash | Array, Array, _]
            pick.reduce(data) do |acc, key|
              case acc
              in Hash if acc.key?(key)
                acc.fetch(key)
              in Array if key.is_a?(Integer) && key < acc.length
                acc[key]
              else
                return blk.nil? ? sentinel : blk.call
              end
            end
          in _
            blk.nil? ? sentinel : blk.call
          end
        end