
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 Pragmatic Bookshelf topics

Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks”
While running the smoke tests in Chapter 2, I get these...
New

Hi Brian,
Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New

Title: Web Development with Clojure, Third Edition - migrations/create not working: p159
When I execute the command:
user=> (create-...
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

Title: Hands-on Rust: question about get_component (page 295)
(feel free to respond. “You dug you’re own hole… good luck”)
I have somet...
New

On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New

Title: Intuitive Python: docker run… denied error (page 2)
Attempted to run the docker command in both CLI and Powershell
PS C:\Users\r...
New

When trying to generate the protobuf .go file, I receive this error:
Unknown flag: --go_opt
libprotoc 3.12.3
MacOS 11.3.1
Googling ...
New

When installing Cards as an editable package, I get the following error:
ERROR: File “setup.py” not found. Directory cannot be installe...
New

@mfazio23
I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New
Other popular topics

Any thoughts on Svelte?
Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New

I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New

New

You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
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

Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New

Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

The File System Access API with Origin Private File System.
WebKit supports new API that makes it possible for web apps to create, open,...
New

This is cool!
DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON
We just witnessed something incredible: the largest open-s...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /java
- /haskell
- /onivim
- /svelte
- /typescript
- /crystal
- /c-plus-plus
- /kotlin
- /tailwind
- /gleam
- /react
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /centos
- /php
- /deepseek
- /html
- /scala
- /zig
- /sublime-text
- /textmate
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /django
- /manjaro
- /spring
- /diversity
- /nodejs
- /lua
- /c
- /julia
- /slackware
- /markdown