public static Writer <Out, Reader <E, V> > SelectMany <Out, E, T, U, V>( this Writer <Out, T> self, Func <T, Reader <E, U> > bind, Func <T, U, V> project ) { if (bind == null) { throw new ArgumentNullException("bind"); } if (project == null) { throw new ArgumentNullException("project"); } return(() => { var resT = self(); if (resT.IsBottom) { return WriterResult.Bottom <Out, Reader <E, V> >(resT.Output); } return WriterResult.Return <Out, Reader <E, V> >(env => { var resU = bind(resT.Value)(env); if (resU.IsBottom) { return ReaderResult.Bottom <V>(); } return ReaderResult.Return(project(resT.Value, resU.Value)); }, resT.Output); }); }
private static ReaderResult <T> Bottom <T>() => ReaderResult.Bottom <T>();