Skip to content

Instantly share code, notes, and snippets.

@lumie1337
Last active June 17, 2020 01:53
Show Gist options
  • Select an option

  • Save lumie1337/f438394a5f9157e4c0dce54a61e78787 to your computer and use it in GitHub Desktop.

Select an option

Save lumie1337/f438394a5f9157e4c0dce54a61e78787 to your computer and use it in GitHub Desktop.
module FoldTogether where
import Prelude
import Data.Foldable
import Data.Array
import Data.Array.NonEmpty as N
import Control.Bind
chunksOf_ n [] = []
chunksOf_ n xs = take n xs:chunksOf_ n (drop n xs)
foldTogether xs = group xs >>= (N.toArray >>> chunksOf_ 2 >>> map sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment