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
class NutrionFacts(builder: NutrionFacts.Builder) { | |
val servingSize: Int = builder.servingSize | |
val sergings: Int = builder.sergings | |
val calories: Int = builder.calories | |
val fat: Int = builder.fat | |
val sodium: Int = builder.sodium | |
val carbohydrate: Int = builder.carbohydrate | |
} | |
object NutrionFacts { |
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
case class NutritionFacts( | |
servingSize: Int, | |
servings: Int, | |
calories: Int = 0, | |
fat: Int = 0, | |
sodium: Int = 0, | |
carbohydrate: Int = 0 | |
) | |
val nf = NutritionFacts(1, 1, fat = 10) |
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
class NutritionFacts { | |
private final int servingSize; | |
private final int servings; | |
private final int calories; | |
private final int fat; | |
private final int sodium; | |
private final int carbohydrate; | |
public static class Builder { | |
// 必須パラメータ |
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
class NutritionFacts { | |
private int servingSize = -1; // 必須 | |
private int servings = -1; // 必須 | |
private int calories = 0; // オプション | |
private int fat = 0; // オプション | |
private int sodium = 0; // オプション | |
private int carbohydrate = 0; // オプション | |
public void setServingSize(int servingSize) { | |
this.servingSize = servingSize; |
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
class NutritionFacts { | |
private final int servingSize; // 必須 | |
private final int servings; // 必須 | |
private final int calories; // オプション | |
private final int fat; // オプション | |
private final int sodium; // オプション | |
private final int carbohydrate; // オプション | |
public NutritionFacts(int servingSize, int servings) { | |
this(servingSize, servings, 0); |
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
flip' :: (a -> b -> c) -> (b -> a -> c) | |
flip' f = g | |
where g x y = f y x |
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)) |
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
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] | |
zipWith' _ [] _ = [] | |
zipWith' _ _ [] = [] | |
zipWith' f (x : xs) (y : ys) = f x y : zipWith' f xs ys |
NewerOlder