示例#1
0
        private static WriterEntriesEntries MergeEntries(ListMonoid <Entry> e1, ListMonoid <Entry> e2)
        {
            if (e1.List.Count == 0)
            {
                return(WriterEntries.Return(e2));
            }
            if (e2.List.Count == 0)
            {
                return(WriterEntries.Return(e1));
            }

            if (e1.List.Count == 1 && e2.List.Count == 1)
            {
                var n1   = e1.List[0].Count;
                var msg1 = e1.List[0].Msg;
                var n2   = e2.List[0].Count;
                var msg2 = e2.List[0].Msg;

                return((msg1 == msg2)
                           ? WriterEntries.Return(new ListMonoid <Entry>(new Entry(n1 + n2, msg1)))
                           : from _ in WriterEntries.Tell(e1)
                       select e2);
            }

            throw new InvalidOperationException("MergeEntries: non-exhaustive patterns");
        }
示例#2
0
        private static Writer <ListMonoid <Entry>, Entry, List <Maybe <Packet> > > GroupSame(
            ListMonoid <Entry> initial,
            Func <ListMonoid <Entry>, ListMonoid <Entry>, Writer <ListMonoid <Entry>, Entry, ListMonoid <Entry> > > merge,
            List <Packet> packets,
            Func <Packet, Writer <ListMonoid <Entry>, Entry, Maybe <Packet> > > fn)
        {
            if (!packets.Any())
            {
                return(from _ in WriterEntries.Tell(initial)
                       select new List <Maybe <Packet> >());
            }

            var x  = packets.First();
            var xs = packets.Skip(1).ToList();

            return(from tuple in WriterEntries.Return(fn(x).RunWriter)
                   let result = tuple.Item1
                                let output = tuple.Item2
                                             let localxs = xs
                                                           let localfn = fn
                                                                         let localinitial = initial
                                                                                            from @new in merge(localinitial, output)
                                                                                            from rest in GroupSame(@new, merge, localxs, localfn)
                                                                                            select Enumerable.Repeat(result, 1).Concat(rest).ToList());
        }
示例#3
0
 private static WriterEntriesUnit LogMsg(string s)
 {
     return(WriterEntries.Tell(new ListMonoid <Entry>(new Entry(1, s))));
 }