Skip to content

add a toString : List Block -> String function #112

@sebsheep

Description

@sebsheep

It would be nice having a toString : List Block -> String function which is a "reverse" of the parser.

Of course some data as indentation could be lost, but I think this manageable.

My use case and wished workflow is the following:

  • an admin writes some article in a form. This content of the textarea is transformed to List Block
  • this List Block is stored as it in the persistence layer (I'm using Lamdera)
  • when a user wants to see the article, we just have to render it with a List Block -> Html renderer.
  • the next time an admin wants to edit the article, we could the string thanks to the toString function and we'd put this in a textarea.

We could just storing the string as it is entered by the admin but:

  • this asks an extra parsing step for the user to view it. It of course seems an inefficient process but what mostly bothers me is that we could have an Err during the process... What do we display to the user in this case?
  • directly storing the List Block value automatically provides a formater, so all the contents are eventually uniformly displayed to the admin.
  • this feature could be a good spot for property testing (the property being: forall blocks : List Block, blocks |> toString |> parse == Ok blocks. And it is always cool writing property tests :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions