Skip to content

Instantly share code, notes, and snippets.

@rinotc
Created Apr 29, 2021
Embed
What would you like to do?
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