Skip to content

Instantly share code, notes, and snippets.

@joneshf
Created May 7, 2018 14:36
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 joneshf/13888e9c8d3d231297cddb760891f944 to your computer and use it in GitHub Desktop.
Save joneshf/13888e9c8d3d231297cddb760891f944 to your computer and use it in GitHub Desktop.
module Main where
import Prelude
import Data.Foldable (class Foldable, foldl)
import Data.Maybe (Maybe(Just, Nothing))
data NonEmpty a = NonEmpty a (Array a)
instance foldableNonEmpty :: Foldable NonEmpty where
foldl f acc (NonEmpty a as) = case ?somethingThatGivesAMaybe as of
Just x -> foldl f (f acc a) (NonEmpty x.head x.tail)
Nothing -> f acc a
foldr = ?foldr
foldMap = ?foldMap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment