-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add navigation for browsing between comments
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Shared.Utils.ListUtils exposing (findNextInfinite, findPreviousInfinite) | ||
|
||
import List.Extra as List | ||
|
||
|
||
findPrevious : a -> List a -> Maybe a | ||
findPrevious item list = | ||
case list of | ||
x :: y :: rest -> | ||
if item == y then | ||
Just x | ||
|
||
else | ||
findPrevious item (y :: rest) | ||
|
||
_ -> | ||
Nothing | ||
|
||
|
||
findPreviousInfinite : a -> List a -> Maybe a | ||
findPreviousInfinite item list = | ||
if List.head list == Just item then | ||
List.last list | ||
|
||
else | ||
findPrevious item list | ||
|
||
|
||
findNext : a -> List a -> Maybe a | ||
findNext item list = | ||
case list of | ||
x :: y :: rest -> | ||
if item == x then | ||
Just y | ||
|
||
else | ||
findNext item (y :: rest) | ||
|
||
_ -> | ||
Nothing | ||
|
||
|
||
findNextInfinite : a -> List a -> Maybe a | ||
findNextInfinite item list = | ||
if List.last list == Just item then | ||
List.head list | ||
|
||
else | ||
findNext item list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters