├── global.json
├── MoreLinq
├── key.snk
├── tt.sh
├── tt.cmd
├── OrderByDirection.cs
├── ReverseComparer.cs
├── Consume.cs
├── Experimental
│ └── ExperimentalEnumerable.cs
├── AssemblyInfo.cs
├── Evaluate.cs
├── GenerateByIndex.cs
├── MoreEnumerable.cs
├── SkipLast.cs
├── Prepend.cs
├── TakeEvery.cs
├── Acquire.cs
├── ListLike.cs
├── Pipe.cs
├── Generate.cs
├── NestedLoops.cs
├── Append.cs
├── ForEach.cs
├── TakeLast.cs
├── Index.cs
├── Exclude.cs
├── Repeat.cs
├── ToHashSet.cs
├── Choose.cs
├── SequenceException.cs
├── ToDelimitedString.cs
├── Fold.g.tt
├── TagFirstLast.cs
├── Pairwise.cs
├── Slice.cs
├── Shuffle.cs
└── ZipImpl.cs
├── .editorconfig
├── pack.sh
├── MoreLinq.Test
├── Program.cs
├── Combinatorics.cs
├── Comparer.cs
├── TestException.cs
├── BreakingReadOnlyList.cs
├── KeyValuePair.cs
├── AssertThrowsArgument.cs
├── BreakingList.cs
├── Scope.cs
├── ConsumeTest.cs
├── EqualityComparer.cs
├── BreakingReadOnlyCollection.cs
├── BreakingSequence.cs
├── CurrentThreadCultureScope.cs
├── ForEachTest.cs
├── BreakingAction.cs
├── PairwiseTest.cs
├── BreakingFunc.cs
├── BreakingCollection.cs
├── ToDelimitedStringTest.cs
├── SampleData.cs
├── SkipLastTest.cs
├── WatchableEnumerator.cs
├── EvaluateTest.cs
├── PipeTest.cs
├── IndexTest.cs
├── TakeUntilTest.cs
├── SkipUntilTest.cs
├── FillBackwardTest.cs
├── GenerateTest.cs
├── DistinctByTest.cs
├── TakeEveryTest.cs
├── SplitTest.cs
├── TagFirstLastTest.cs
├── PreScanTest.cs
├── AssertTest.cs
├── ShuffleTest.cs
├── ExactlyTest.cs
├── PadTest.cs
├── BacksertTest.cs
├── CountBetweenTest.cs
├── ExceptByTest.cs
├── AcquireTest.cs
├── TakeLastTest.cs
├── WindowLeftTest.cs
├── ScanTest.cs
├── WindowRightTest.cs
├── AtMostTest.cs
├── ChooseTest.cs
├── FallbackIfEmptyTest.cs
├── TestingSequence.cs
├── ToDictionaryTest.cs
├── BatchTest.cs
├── InsertTest.cs
├── PrependTest.cs
├── AppendTest.cs
└── UnfoldTest.cs
├── pack.cmd
├── .gitattributes
├── bld
├── ExtensionsGenerator
│ └── MoreLinq.ExtensionsGenerator.csproj
└── Copyright.props
├── test.sh
├── test.cmd
├── .gitignore
├── msbuild.cmd
├── .travis.yml
├── appveyor.yml
└── MoreLinq.sln
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "2.1.500"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/MoreLinq/key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fsateler/MoreLINQ/HEAD/MoreLinq/key.snk
--------------------------------------------------------------------------------
/MoreLinq/tt.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 | cd "$(dirname "$0")"
4 | find . -name "*.tt" -print0 | xargs -0 -t -L 1 sh -c '(dotnet tt "$0" || exit 255)'
5 |
--------------------------------------------------------------------------------
/MoreLinq/tt.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd "%~dp0"
3 | for /f "tokens=*" %%f in ('dir /s /b *.tt') do (
4 | echo>&2 dotnet tt "%%f"
5 | dotnet tt "%%f" || goto :end
6 | )
7 | :end
8 | popd
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | insert_final_newline = true
5 | trim_trailing_whitespace = true
6 |
7 | [*.xml]
8 | indent_style = space
9 |
10 | [*.{cs,tt}]
11 | charset = utf-8
12 | indent_style = space
13 | indent_size = 4
14 |
--------------------------------------------------------------------------------
/pack.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 | cd "$(dirname "$0")"
4 | VERSION_SUFFIX=
5 | if [ ! -z "$1" ]; then VERSION_SUFFIX="--version-suffix $1"; fi
6 | ./build.sh
7 | if [ ! -d dist ]; then mkdir dist; fi
8 | ./msbuild.sh /v:m /t:Pack \
9 | /p:Configuration=Release \
10 | $VERSION_SUFFIX \
11 | MoreLinq/MoreLinq.csproj
12 |
--------------------------------------------------------------------------------
/MoreLinq.Test/Program.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System;
4 | using System.Reflection;
5 | using NUnit.Common;
6 | using NUnitLite;
7 |
8 | static class Program
9 | {
10 | static int Main(string[] args) =>
11 | new AutoRun(typeof(Program).GetTypeInfo().Assembly)
12 | .Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/pack.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd "%~dp0"
3 | call :main %*
4 | popd
5 | goto :EOF
6 |
7 | :main
8 | setlocal
9 | if not exist dist md dist
10 | if not %errorlevel%==0 exit /b %errorlevel%
11 | set VERSION_SUFFIX=
12 | if not "%~1"=="" set VERSION_SUFFIX=/p:VersionSuffix=%1
13 | call build ^
14 | && dotnet pack /p:Configuration=Release ^
15 | %VERSION_SUFFIX% ^
16 | MoreLinq\MoreLinq.csproj
17 | goto :EOF
18 |
--------------------------------------------------------------------------------
/MoreLinq.Test/Combinatorics.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace MoreLinq.Test
3 | {
4 | static class Combinatorics
5 | {
6 | public static double Factorial(int n)
7 | {
8 | var fac = 1.0d;
9 | while (n > 0)
10 | fac *= n--;
11 | return fac;
12 | }
13 |
14 | public static double Binomial(int n, int k) =>
15 | Factorial(n) / (Factorial(n - k) * Factorial(k));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | *.sh eol=lf
5 |
6 | # Custom for Visual Studio
7 | *.cs diff=csharp
8 |
9 | # Standard to msysgit
10 | *.doc diff=astextplain
11 | *.DOC diff=astextplain
12 | *.docx diff=astextplain
13 | *.DOCX diff=astextplain
14 | *.dot diff=astextplain
15 | *.DOT diff=astextplain
16 | *.pdf diff=astextplain
17 | *.PDF diff=astextplain
18 | *.rtf diff=astextplain
19 | *.RTF diff=astextplain
20 |
--------------------------------------------------------------------------------
/bld/ExtensionsGenerator/MoreLinq.ExtensionsGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -e
3 | cd "$(dirname "$0")"
4 | ./build.sh
5 | for v in 1.0 2.0 2.1; do
6 | for c in Debug Release; do
7 | dotnet exec MoreLinq.Test/bin/$c/netcoreapp$v/MoreLinq.Test.dll
8 | done
9 | done
10 | if [[ -z `which mono 2>/dev/null` ]]; then
11 | echo>&2 NOTE! Mono does not appear to be installed so unit tests
12 | echo>&2 against the Mono runtime will be skipped.
13 | else
14 | mono MoreLinq.Test/bin/Debug/net451/MoreLinq.Test.exe
15 | mono MoreLinq.Test/bin/Release/net451/MoreLinq.Test.exe
16 | fi
17 |
--------------------------------------------------------------------------------
/bld/Copyright.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | © 2008 Jonathan Skeet.
5 | Portions © 2009 Atif Aziz, Chris Ammerman, Konrad Rudolph.
6 | Portions © 2010 Johannes Rudolph, Leopold Bushkin.
7 | Portions © 2015 Felipe Sateler, “sholland”.
8 | Portions © 2016 Andreas Gullberg Larsen, Leandro F. Vieira (leandromoh).
9 | Portions © 2017 Jonas Nyrup (jnyrup).
10 | Portions © Microsoft. All rights reserved.
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | pushd "%~dp0"
3 | call :main %*
4 | popd
5 | goto :EOF
6 |
7 | :main
8 | setlocal
9 | call build ^
10 | && call :test netcoreapp1.0 Debug ^
11 | && call :test netcoreapp1.0 Release ^
12 | && call :test netcoreapp2.0 Debug ^
13 | && call :test netcoreapp2.0 Release ^
14 | && call :test netcoreapp2.1 Debug ^
15 | && call :test netcoreapp2.1 Release ^
16 | && call :test net451 Debug ^
17 | && call :test net451 Release
18 | goto :EOF
19 |
20 | :test
21 | setlocal
22 | echo Testing %1 (%2)...
23 | if %1==net451 (
24 | MoreLinq.Test\bin\%2\net451\MoreLinq.Test.exe
25 | ) else (
26 | dotnet exec MoreLinq.Test\bin\%2\%1\MoreLinq.Test.dll
27 | )
28 | goto :EOF
29 |
--------------------------------------------------------------------------------
/MoreLinq.Test/Comparer.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | sealed class Comparer
7 | {
8 | ///
9 | /// Creates an given a
10 | /// .
11 | ///
12 |
13 | public static IComparer Create(Func compare) =>
14 | new DelegatingComparer(compare);
15 |
16 | sealed class DelegatingComparer : IComparer
17 | {
18 | readonly Func _comparer;
19 |
20 | public DelegatingComparer(Func comparer)
21 | {
22 | _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
23 | }
24 |
25 | public int Compare(T x, T y) => _comparer(x, y);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### VisualStudio ###
2 | ## Ignore Visual Studio temporary files, build results, and
3 | ## files generated by popular Visual Studio add-ons.
4 |
5 | # User-specific files
6 | *.suo
7 | *.user
8 | *.userosscache
9 | *.sln.docstates
10 |
11 | # Build results
12 | [Dd]ebug/
13 | [Dd]ebugPublic/
14 | [Rr]elease/
15 | [Rr]eleases/
16 | x64/
17 | x86/
18 | build/
19 | [Bb]in/
20 | [Oo]bj/
21 |
22 | # Visual Studio 2015 cache/options directory
23 | .vs/
24 |
25 | # NUNIT
26 | *.VisualState.xml
27 | TestResult.xml
28 |
29 | # ReSharper
30 | _ReSharper*/
31 | *.[Rr]e[Ss]harper
32 | *.DotSettings.user
33 |
34 | # CodeRush
35 | **/\.cr/
36 |
37 | NuGet Packages
38 | *.nupkg
39 | # The packages folder can be ignored because of Package Restore
40 | **/packages/*
41 | # except build/, which is used as an MSBuild target.
42 | !**/packages/build/
43 |
44 | docs/
45 |
46 | .vscode/
47 | *.lock.json
48 | tools/
49 |
50 | # IntelliJ Platform excludes
51 |
52 | .idea/
53 |
54 |
--------------------------------------------------------------------------------
/MoreLinq.Test/TestException.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2012 Atif Aziz. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | ///
21 | /// Reserved for use within tests.
22 | ///
23 |
24 | sealed class TestException : System.Exception {}
25 | }
26 |
--------------------------------------------------------------------------------
/MoreLinq.Test/BreakingReadOnlyList.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | ///
7 | /// This class implement but specifically prohibits enumeration using GetEnumerator().
8 | /// It is provided to assist in testing extension methods that MUST NOT call the GetEnumerator()
9 | /// method of - either because they should be using the indexer or because they are
10 | /// expected to be lazily evaluated.
11 | ///
12 |
13 | sealed class BreakingReadOnlyList : BreakingReadOnlyCollection, IReadOnlyList
14 | {
15 | readonly IReadOnlyList _list;
16 |
17 | public BreakingReadOnlyList(params T[] values) : this ((IReadOnlyList) values) {}
18 | public BreakingReadOnlyList(IReadOnlyList list) : base (list)
19 | => _list = list;
20 |
21 | public T this[int index] => _list[index];
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/MoreLinq.Test/KeyValuePair.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System.Collections.Generic;
21 |
22 | static class KeyValuePair
23 | {
24 | public static KeyValuePair Create(TKey key, TValue value) =>
25 | new KeyValuePair(key, value);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MoreLinq.Test/AssertThrowsArgument.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System;
4 | using NUnit.Framework;
5 |
6 | sealed class AssertThrowsArgument
7 | {
8 | [Obsolete("This is redundant with the NullArgumentTest fixture.")]
9 | public static void NullException(string expectedParamName, TestDelegate code)
10 | {
11 | Exception(expectedParamName, code);
12 | }
13 |
14 | public static void Exception(string expectedParamName, TestDelegate code)
15 | {
16 | Exception(expectedParamName, code);
17 | }
18 |
19 | public static void OutOfRangeException(string expectedParamName, TestDelegate code)
20 | {
21 | Exception(expectedParamName, code);
22 | }
23 |
24 | static void Exception(string expectedParamName, TestDelegate code) where TActual : ArgumentException
25 | {
26 | var e = Assert.Throws(code);
27 |
28 | Assert.That(e.ParamName, Is.EqualTo(expectedParamName));
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MoreLinq.Test/BreakingList.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 |
7 | ///
8 | /// This class implement but specifically prohibits enumeration using GetEnumerator().
9 | /// It is provided to assist in testing extension methods that MUST NOT call the GetEnumerator()
10 | /// method of - either because they should be using the indexer or because they are
11 | /// expected to be lazily evaluated.
12 | ///
13 |
14 | sealed class BreakingList : BreakingCollection, IList
15 | {
16 | public BreakingList() : this(new List()) {}
17 | public BreakingList(List list) : base(list) {}
18 |
19 | public int IndexOf(T item) => List.IndexOf(item);
20 | public void Insert(int index, T item) => throw new NotImplementedException();
21 | public void RemoveAt(int index) => throw new NotImplementedException();
22 |
23 | public T this[int index]
24 | {
25 | get => List[index];
26 | set => throw new NotImplementedException();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MoreLinq.Test/Scope.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System;
21 |
22 | abstract class Scope : IDisposable
23 | {
24 | readonly T _old;
25 |
26 | protected Scope(T current)
27 | {
28 | _old = current;
29 | }
30 |
31 | public virtual void Dispose()
32 | {
33 | Restore(_old);
34 | }
35 |
36 | protected abstract void Restore(T old);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MoreLinq.Test/ConsumeTest.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using NUnit.Framework;
21 |
22 | [TestFixture]
23 | public class ConsumeTest
24 | {
25 | [Test]
26 | public void ConsumeReallyConsumes()
27 | {
28 | var counter = 0;
29 | var sequence = Enumerable.Range(0, 10).Pipe(x => counter++);
30 | sequence.Consume();
31 | Assert.AreEqual(10, counter);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MoreLinq.Test/EqualityComparer.cs:
--------------------------------------------------------------------------------
1 | namespace MoreLinq.Test
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | static class EqualityComparer
7 | {
8 | ///
9 | /// Creates an given a
10 | /// .
11 | ///
12 |
13 | public static IEqualityComparer Create(Func comparer) =>
14 | new DelegatingComparer(comparer);
15 |
16 | sealed class DelegatingComparer : IEqualityComparer
17 | {
18 | readonly Func _comparer;
19 | readonly Func _hasher;
20 |
21 | public DelegatingComparer(Func comparer)
22 | : this(comparer, x => x == null ? 0 : x.GetHashCode()) {}
23 |
24 | DelegatingComparer(Func comparer, Func hasher)
25 | {
26 | _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
27 | _hasher = hasher ?? throw new ArgumentNullException(nameof(hasher));
28 | }
29 |
30 | public bool Equals(T x, T y) => _comparer(x, y);
31 | public int GetHashCode(T obj) => _hasher(obj);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MoreLinq/OrderByDirection.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2010 Leopold Bushkin. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq
19 | {
20 | ///
21 | /// Enumeration that defines values representing valid ordering directions for a sequence.
22 | ///
23 |
24 | public enum OrderByDirection
25 | {
26 | ///
27 | /// Elements are ordered by increasing value
28 | ///
29 | Ascending = 0,
30 | ///
31 | /// Elements are ordered by decreasing value
32 | ///
33 | Descending = 1,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MoreLinq/ReverseComparer.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2016 Felipe Sateler. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq
19 | {
20 | using System.Collections.Generic;
21 |
22 | sealed class ReverseComparer : IComparer
23 | {
24 | readonly IComparer _underlying;
25 |
26 | public ReverseComparer(IComparer underlying)
27 | {
28 | _underlying = underlying ?? Comparer.Default;
29 | }
30 |
31 | public int Compare(T x, T y)
32 | {
33 | var result = _underlying.Compare(x, y);
34 | return result < 0 ? 1 : result > 0 ? -1 : 0;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MoreLinq.Test/BreakingReadOnlyCollection.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System;
21 | using System.Collections.Generic;
22 |
23 | class BreakingReadOnlyCollection : BreakingSequence, IReadOnlyCollection
24 | {
25 | readonly IReadOnlyCollection _collection;
26 |
27 | public BreakingReadOnlyCollection(params T[] values) : this ((IReadOnlyCollection) values) {}
28 | public BreakingReadOnlyCollection(IReadOnlyCollection collection) => _collection = collection;
29 | public int Count => _collection.Count;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MoreLinq.Test/BreakingSequence.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System;
21 | using System.Collections;
22 | using System.Collections.Generic;
23 |
24 | ///
25 | /// Enumerable sequence which throws InvalidOperationException as soon as its
26 | /// enumerator is requested. Used to check lazy evaluation.
27 | ///
28 | class BreakingSequence : IEnumerable
29 | {
30 | public IEnumerator GetEnumerator() => throw new InvalidOperationException();
31 | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MoreLinq.Test/CurrentThreadCultureScope.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System.Globalization;
21 |
22 | sealed class CurrentThreadCultureScope : Scope
23 | {
24 | public CurrentThreadCultureScope(CultureInfo @new) :
25 | base(CultureInfo.CurrentCulture)
26 | {
27 | Install(@new);
28 | }
29 |
30 | protected override void Restore(CultureInfo old)
31 | {
32 | Install(old);
33 | }
34 |
35 | static void Install(CultureInfo value)
36 | {
37 | #if NET451
38 | System.Threading.Thread.CurrentThread.CurrentCulture = value;
39 | #else
40 | CultureInfo.CurrentCulture = value;
41 | #endif
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MoreLinq/Consume.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq
19 | {
20 | using System;
21 | using System.Collections.Generic;
22 |
23 | static partial class MoreEnumerable
24 | {
25 | ///
26 | /// Completely consumes the given sequence. This method uses immediate execution,
27 | /// and doesn't store any data during execution.
28 | ///
29 | /// Element type of the sequence
30 | /// Source to consume
31 |
32 | public static void Consume(this IEnumerable source)
33 | {
34 | if (source == null) throw new ArgumentNullException(nameof(source));
35 | foreach (var element in source)
36 | {
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MoreLinq/Experimental/ExperimentalEnumerable.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2018 Atif Aziz. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Experimental
19 | {
20 | using System.Collections.Generic;
21 |
22 | ///
23 | ///
24 | /// Provides a set of static methods for querying objects that
25 | /// implement .
26 | ///
27 | /// THE METHODS ARE EXPERIMENTAL. THEY MAY BE UNSTABLE AND
28 | /// UNTESTED. THEY MAY BE REMOVED FROM A FUTURE MAJOR OR MINOR RELEASE AND
29 | /// POSSIBLY WITHOUT NOTICE. USE THEM AT YOUR OWN RISK. THE METHODS ARE
30 | /// PUBLISHED FOR FIELD EXPERIMENTATION TO SOLICIT FEEDBACK ON THEIR
31 | /// UTILITY AND DESIGN/IMPLEMENTATION DEFECTS.
32 | ///
33 |
34 | public static partial class ExperimentalEnumerable
35 | {
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MoreLinq/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | using System;
19 | using System.Reflection;
20 | using System.Runtime.InteropServices;
21 |
22 | [assembly: AssemblyTitle("MoreLINQ")]
23 | [assembly: AssemblyDescription("Extensions to LINQ to Objects")]
24 | [assembly: AssemblyCompany("")]
25 | [assembly: AssemblyProduct("MoreLINQ")]
26 | [assembly: AssemblyTrademark("")]
27 | [assembly: AssemblyCulture("")]
28 |
29 | // Debug or release configuration?
30 |
31 | #if DEBUG
32 | [assembly: AssemblyConfiguration("DEBUG")]
33 | #else
34 | [assembly: AssemblyConfiguration("RELEASE")]
35 | #endif
36 |
37 | // CLS compliance and COM visibility
38 |
39 | [assembly: CLSCompliant(true)]
40 | #if !NO_COM
41 | [assembly: ComVisible(false)]
42 |
43 | // ID of the typelib if this project is exposed to COM.
44 |
45 | [assembly: Guid("fc632c9d-390e-4902-8c1c-3e57b08c1d38")]
46 | #endif
47 |
--------------------------------------------------------------------------------
/msbuild.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 | if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
4 | if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
5 | for %%e in (Community Professional Enterprise) do (
6 | if exist "%PROGRAMS%\Microsoft Visual Studio\2017\%%e\MSBuild\15.0\Bin\MSBuild.exe" (
7 | set "MSBUILD=%PROGRAMS%\Microsoft Visual Studio\2017\%%e\MSBuild\15.0\Bin\MSBuild.exe"
8 | )
9 | )
10 | if exist "%MSBUILD%" goto :build
11 | set MSBUILD=
12 | for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
13 | if not defined MSBUILD goto :nomsbuild
14 | set MSBUILD_VERSION_MAJOR=
15 | set MSBUILD_VERSION_MINOR=
16 | for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
17 | set MSBUILD_VERSION_MAJOR=%%m
18 | set MSBUILD_VERSION_MINOR=%%n
19 | )
20 | if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
21 | if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
22 | if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
23 | if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
24 | :build
25 | "%MSBUILD%" %*
26 | goto :EOF
27 |
28 | :nomsbuild
29 | echo>&2 Microsoft Build Engine 15.1 is required to build the solution. For
30 | echo>&2 installation instructions, see:
31 | echo>&2 https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio
32 | echo>&2 At the very least, you will want to install the MSBuilt Tool workload
33 | echo>&2 that has the identifier "Microsoft.VisualStudio.Workload.MSBuildTools":
34 | echo>&2 https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools#msbuild-tools
35 | exit /b s
36 |
--------------------------------------------------------------------------------
/MoreLinq.Test/ForEachTest.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System.Collections.Generic;
21 | using NUnit.Framework;
22 |
23 | [TestFixture]
24 | public class ForEachTest
25 | {
26 | [Test]
27 | public void ForEachWithSequence()
28 | {
29 | var results = new List();
30 | new[] { 1, 2, 3 }.ForEach(results.Add);
31 | results.AssertSequenceEqual(1, 2, 3);
32 | }
33 |
34 | [Test]
35 | public void ForEachIndexedWithSequence()
36 | {
37 | var valueResults = new List();
38 | var indexResults = new List();
39 | new[] { 9, 7, 8 }.ForEach((x, index) => { valueResults.Add(x); indexResults.Add(index); });
40 | valueResults.AssertSequenceEqual(9, 7, 8);
41 | indexResults.AssertSequenceEqual(0, 1, 2);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MoreLinq.Test/BreakingAction.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2018 Leandro F. Vieira (leandromoh). All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using System;
21 |
22 | ///
23 | /// Actions which throw NotImplementedException if they're ever called.
24 | ///
25 | static class BreakingAction
26 | {
27 | internal static Action WithoutArguments =>
28 | () => throw new NotImplementedException();
29 |
30 | internal static Action Of() =>
31 | t => throw new NotImplementedException();
32 |
33 | internal static Action Of() =>
34 | (t1, t2) => throw new NotImplementedException();
35 |
36 | internal static Action Of() =>
37 | (t1, t2, t3) => throw new NotImplementedException();
38 |
39 | internal static Action Of() =>
40 | (t1, t2, t3, t4) => throw new NotImplementedException();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MoreLinq.Test/PairwiseTest.cs:
--------------------------------------------------------------------------------
1 | #region License and Terms
2 | // MoreLINQ - Extensions to LINQ to Objects
3 | // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | #endregion
17 |
18 | namespace MoreLinq.Test
19 | {
20 | using NUnit.Framework;
21 |
22 | [TestFixture]
23 | public class PairwiseTest
24 | {
25 | [Test]
26 | public void PairwiseIsLazy()
27 | {
28 | new BreakingSequence