Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created October 22, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/c22e48e6e12f06f794f94ba8a3272681 to your computer and use it in GitHub Desktop.
Save tonymorris/c22e48e6e12f06f794f94ba8a3272681 to your computer and use it in GitHub Desktop.
nonEmptyIso ::
Iso [a] [b] (Maybe (NonEmpty a)) (Maybe (NonEmpty b))
nonEmptyIso =
iso
(
\case
[] ->
Nothing
h:t ->
Just (h:|t)
)
(
\case
Nothing ->
[]
Just (h:|t) ->
h:t
)
blah ::
[Maybe a]
-> Maybe (NonEmpty a)
blah =
view nonEmptyIso . catMaybes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment