# Exploring Graphs with Elixir: case clause for already sliced graph.data string p25

**URL:** <https://forum.devtalk.com/t/exploring-graphs-with-elixir-case-clause-for-already-sliced-graph-data-string-p25/10140>\
**Category:** PragProg Customers\
**Tags:** book-exploring-graphs-with-elixir, errata\
**Created:** [2 June 2021 13:39 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-case-clause-for-already-sliced-graph-data-string-p25/10140 "2021-06-02T13:39:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mvellandi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mvellandi/32/2726_2.png) [@mvellandi](https://forum.devtalk.com/u/mvellandi)\
**Post date:** [18 June 2021 09:44 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-case-clause-for-already-sliced-graph-data-string-p25/10140/2 "2021-06-18T09:44:46Z")

</div>

We’re talking about the Inspect implementation for a graph struct, right?  
The length of str can surely be less than a defined @slice value.

```auto
slice = 16
str = "magic broom"
str = str |> String.slice(0, slice)
String.length(str) < slice
=> true

```

Here’s my implementation which I believe I copied without mods

```auto
defimpl Inspect, for: __MODULE__ do
    @slice 16
    @quote <<?">>

    def inspect(%GraphCommons.Graph{} = graph, _opts) do
      type = graph.type
      file = @quote <> graph.file <> @quote

      str =
        graph.data
        |> String.replace("\n", "\\n")
        |> String.replace(@quote, "\\" <> @quote)
        |> String.slice(0, @slice)

      data =
        case String.length(str) < @slice do
          true -> @quote <> str <> @quote
          false -> @quote <> str <> "..." <> @quote
        end

      "#GraphCommons.Graph<type: #{type}, file: #{file}, data: #{data}>"
    end
  end

```

---

_[View the full topic](https://forum.devtalk.com/t/exploring-graphs-with-elixir-case-clause-for-already-sliced-graph-data-string-p25/10140)._
