diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:03:56 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-06-04 16:03:56 +0100 |
| commit | 45e530dceda42282fae56b4c4f5fa7865f57899d (patch) | |
| tree | 685868f4bf78c64e851cbcdafd674e887bc782a5 /dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs | |
| parent | b5a83b1cb96d410e325ff8b733d550295376d8c7 (diff) | |
Remove dotnet (use submodule from dotnet repo instead)
Diffstat (limited to 'dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs')
| -rw-r--r-- | dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs b/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs deleted file mode 100644 index b914a34..0000000 --- a/dotnet/Mammoth/Couscous/mammoth/internal/util/Lists.cs +++ /dev/null @@ -1,97 +0,0 @@ -using Mammoth.Couscous.java.lang; -using Mammoth.Couscous.java.util; -using Mammoth.Couscous.java.util.function; -using System.Linq; - -namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util { - internal static class Lists { - internal static List<T> list<T>(params T[] values) { - return ToJava.ListToList(values); - } - - internal static List<T> toList<T>(Iterable<T> iterable) { - return ToJava.ListToList(FromJava.IterableToEnumerable(iterable).ToList()); - } - - internal static List<U> eagerMap<T, U>(Iterable<T> iterable, Function<T, U> function) { - var result = FromJava.IterableToEnumerable(iterable) - .Select(function.apply) - .ToList(); - return ToJava.ListToList(result); - } - - internal static List<U> eagerFlatMap<T, U>(Iterable<T> iterable, Function<T, Iterable<U>> function) { - var result = FromJava.IterableToEnumerable(iterable) - .SelectMany(element => FromJava.IterableToEnumerable(function.apply(element))) - .ToList(); - return ToJava.ListToList(result); - } - - internal static List<T> cons<T>(T head, Iterable<T> tail) { - var result = new T[] { head } - .Concat(FromJava.IterableToEnumerable(tail)) - .ToList(); - return ToJava.ListToList(result); - } - - internal static List<T> eagerConcat<T>(Iterable<T> first, Iterable<T> second) { - var result = FromJava.IterableToEnumerable(first) - .Concat(FromJava.IterableToEnumerable(second)) - .ToList(); - return ToJava.ListToList(result); - } - - internal static List<T> orderedBy<T, R>(Iterable<T> iterable, Function<T, R> getKey) { - var result = FromJava.IterableToEnumerable(iterable) - .OrderBy(getKey.apply) - .ToList(); - return ToJava.ListToList(result); - } - - internal static Optional<T> tryGetLast<T>(List<T> list) { - if (list.isEmpty()) { - return new None<T>(); - } else { - return new Some<T>(list.get(list.size() - 1)); - } - } - - internal static Iterable<T> reversed<T>(List<T> list) { - return new ReversedList<T>(list); - } - - private class ReversedList<T> : Iterable<T> { - private readonly List<T> _list; - - internal ReversedList(List<T> list) { - _list = list; - } - - public Iterator<T> iterator() { - return new ReverseIterator<T>(_list); - } - } - - private class ReverseIterator<T> : Iterator<T> { - private readonly List<T> _list; - private int _nextIndex; - - internal ReverseIterator(List<T> list) { - _list = list; - _nextIndex = _list.size() - 1; - } - - public bool hasNext() { - return _nextIndex >= 0; - } - - public T next() { - if (hasNext()) { - return _list.get(_nextIndex--); - } else { - throw new NoSuchElementException(); - } - } - } - } -} |
