Created
April 29, 2021 15:11
-
-
Save rinotc/9c1862d0d11a66c2d56adc9fd203f19a to your computer and use it in GitHub Desktop.
haskell勉強メモ9 zipWith Scala版
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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