π³
π³
π³
π³
Walking though the Elm woods
Searchβ¦
π³
π³
π³
π³
Walking though the Elm woods
Introduction
Structure of the book
Frequently asked questions
How can different types share data?
How to break Dependency Cycles?
How to structure an Elm project?
How to turn a Msg into a Cmd Msg?
How to update nested Records?
What are comparable types?
Why are Booleans bad?
π
Future topics
Recipes
Writing a Single Page Application
Making impossible states Impossible
Non empty lists using Zippers
Restrict records using Opaque Types
Write safer functions using Phantom Types
Designing Elm package APIs
π
Future topics
Frameworks and packages
elm/parser
mdgriffith/elm-ui
π
Future topics
Powered By
GitBook
Non empty lists using Zippers
Problem
Solution
1
type alias Book =
2
List Page
3
β
4
currentPage : Book -> Page
5
currentPage book =
6
case book of
7
page :: _ ->
8
page
9
[] ->
10
Debug.todo "this is a dead end."
11
Copied!
1
type alias Book =
2
{ previous : List Page
3
, current : Page
4
, next : List Page
5
}
6
β
7
currentPage : Book -> Page
8
currentPage book =
9
book.current
Copied!
Question
How can I ensure that a list always contains at least one element.
Answer
Such a list is called a
Zipper List
:
1
type alias ZipperList a =
2
{ previous : List a
3
, current : a
4
, next : List a
5
}
Copied!
Package:
Use
miyamoen/select-list
for a complete implementation of a Zipper List.
Further reading
π¦
Package:
miyamoen/select-list
β
π¦
Package:
wernerdegroot/listzipper
β
Recipes - Previous
Making impossible states Impossible
Next
Restrict records using Opaque Types
Last modified
2yr ago
Copy link
Contents
Question
Answer
Further reading