Skip to content

Instantly share code, notes, and snippets.

@rinotc
Created April 29, 2021 15:11
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 rinotc/9c1862d0d11a66c2d56adc9fd203f19a to your computer and use it in GitHub Desktop.
Save rinotc/9c1862d0d11a66c2d56adc9fd203f19a to your computer and use it in GitHub Desktop.
haskell勉強メモ9 zipWith Scala版
def zipWith[A, B, C](f: (A, B) => C)(listA: List[A])(listB: List[B]): List[C] = {
(listA, listB) match {
case (Nil, _) => Nil
case (_, Nil) => Nil
case (a :: as, b :: bs) => f(a, b) +: zipWith(f)(as)(bs)
}
}
zipWith { (a: Int, b: Int) => a + b }(List(1,2,3))(List(4,5,6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment