
shotleybuilder
Exploring Graphs with Elixir: case clause for already sliced graph.data string p25
The logic to determine if an ellipsis is shown will always evaluate to false because the variable str is already sliced and has a length equal to @slice
My 2p
data =
case String.length(str) < @slice do
true ->
@quote <> str <> @quote
false ->
str
|> String.slice(0, @slice)
|> (&(@quote <> &1 <> "..." <> @quote)).()
end
First Post!

mvellandi
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.
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
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
Popular Prag Prog topics

As per the title, thanks.
New

your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New

Hi Jamis,
I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019.
This test doesn’t pass for me:
...
New

Hi Travis! Thank you for the cool book! :slight_smile:
I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New

I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps.
With:
ruby-3.0.0
s...
New

This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New

Is the book’s epub format available to read on Google Play Books?
New

Hey there,
I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “>...
New

Hi, I’m working on the Chapter 8 of the book.
After I add add the point_offset, I’m still able to see acne:
In the image above, I re...
New

root_layout: {PentoWeb.LayoutView, :root},
This results in the following following error:
no “root” html template defined for PentoWeb...
New
Other popular topics

What chair do you have while working… and why?
Is there a ‘best’ type of chair or working position for developers?
New

New

poll
poll
Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New

Seems like a lot of people caught it - just wondered whether any of you did?
As far as I know I didn’t, but it wouldn’t surprise me if I...
New

A Hero’s Journey
with Chris Pine
@chrispine
Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New

Author Spotlight
James Stanier
@jstanier
James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New

A Brief Review of the Minisforum V3 AMD Tablet.
Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /sublime-text
- /textmate
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /c
- /julia
- /neovim