コード例 #1
0
ファイル: MaybeChef.cs プロジェクト: eshlykov/dotnet-course
        /// <inheritdoc />
        public IImmutableList <PumpkinMuffin> CookPumpkinMuffins()
        {
            var oven = new Oven();

            oven.Heat(166);

            return(MakeFlourMixture()
                   .Select(flourMixture => MakeEggsMixture().Select(eggsMixture => PrepareBackingDish(flourMixture, eggsMixture)))
                   .Select(backingDish => oven.Bake <PumpkinBatterCup, PumpkinMuffin>(backingDish, TimeSpan.FromMinutes(30)).ToMaybe())
                   .SelectOrElse(pumpkinMuffin => pumpkinMuffin.Cups, () => null));
        }
コード例 #2
0
ファイル: MaybeChef.cs プロジェクト: eshlykov/dotnet-course
        /// <inheritdoc />
        public IImmutableList <PumpkinMuffin> CookPumpkinMuffins()
        {
            var oven = new Oven();

            oven.Heat(166);

            var result =
                from flourMixture in MakeFlourMixture()
                from eggsMixture in MakeEggsMixture()
                from backingDish in PrepareBackingDish(flourMixture, eggsMixture)
                from pumpkinMuffins in oven.Bake <PumpkinBatterCup, PumpkinMuffin>(backingDish, TimeSpan.FromMinutes(30)).ToMaybe()
                select pumpkinMuffins.Cups;

            return(result.GetValueOrDefault());
        }
コード例 #3
0
ファイル: MaybeChef.cs プロジェクト: eshlykov/dotnet-course
        /// <inheritdoc />
        public IImmutableList <PumpkinMuffin> CookPumpkinMuffins()
        {
            var oven = new Oven();

            oven.Heat(166);


            var result =
                from flourMixture in MakeFlourMixture()
                from eggsMixture in MakeEggsMixture()
                from backingDish in PrepareBackingDish(flourMixture, eggsMixture)
                from pumpkinMuffins in oven.Bake <PumpkinBatterCup, PumpkinMuffin>(backingDish, TimeSpan.FromMinutes(30)).ToMaybe()
                select pumpkinMuffins.Cups;

            // !!!: result имеет тип IEnumerable<IImmutableList<PumpkinMuffin>>

            // нужно явно вернуться из IEnumerable в Maybe - для этого и нужен соответствующий экстеншн.
            return(result.ToMaybe().GetValueOrDefault());
        }