This commit is contained in:
Tommy Parnell
2015-10-24 20:38:43 -04:00
commit 947c650ad0
13 changed files with 664 additions and 0 deletions

230
.gitignore vendored Normal file
View File

@@ -0,0 +1,230 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Azure Emulator
efc/
rfc/
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
# FAKE - F# Make
.fake/

40
LinqRb.sln Normal file
View File

@@ -0,0 +1,40 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{077EAD3B-238B-482A-9C31-C34326A34814}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E8B97B79-9746-4809-BD83-88D0E4E46467}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.Config = NuGet.Config
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LinqRb", "src\LinqRb\LinqRb.xproj", "{1538FF9B-DE9C-4EA5-95A5-912F016A04DA}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LinqRb.UnitTests", "src\LinqRb.UnitTests\LinqRb.UnitTests.xproj", "{AC5573FD-73C9-47CD-94B8-59B562BC3E54}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1538FF9B-DE9C-4EA5-95A5-912F016A04DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1538FF9B-DE9C-4EA5-95A5-912F016A04DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1538FF9B-DE9C-4EA5-95A5-912F016A04DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1538FF9B-DE9C-4EA5-95A5-912F016A04DA}.Release|Any CPU.Build.0 = Release|Any CPU
{AC5573FD-73C9-47CD-94B8-59B562BC3E54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC5573FD-73C9-47CD-94B8-59B562BC3E54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC5573FD-73C9-47CD-94B8-59B562BC3E54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC5573FD-73C9-47CD-94B8-59B562BC3E54}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1538FF9B-DE9C-4EA5-95A5-912F016A04DA} = {077EAD3B-238B-482A-9C31-C34326A34814}
{AC5573FD-73C9-47CD-94B8-59B562BC3E54} = {077EAD3B-238B-482A-9C31-C34326A34814}
EndGlobalSection
EndGlobal

8
NuGet.Config Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

21
appveyor.yml Normal file
View File

@@ -0,0 +1,21 @@
configuration: Release
version: 0.1.{build}
nuget:
account_feed: true
project_feed: true
init:
- git config --global core.autocrlf true
before_build:
- ps: "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
- ps: dnvm upgrade
- ps: dnvm update-self
- ps: dnvm install 1.0.0-beta8
- ps: dnvm list
- ps: dnvm use 1.0.0-beta8
- ps: dnu restore
- cmd: set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
artifacts:
- path: artifacts\bin\LinqRb\Release\*.nupkg

6
global.json Normal file
View File

@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta8"
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace LinqRb.UnitTests
{
public class EnumerableTest
{
[Fact]
public void TestRejectSuccessful()
{
var range = Enumerable.Range(1, 5);
var rejected = range.Reject(a => a == 3);
foreach(var number in rejected)
{
Assert.NotEqual(number, 3);
}
Assert.True(rejected.Count() == 4);
}
[Fact]
public void TestAssoc()
{
var outer = new List<List<string>>();
outer.Add(new List<string>() { "books", "school", "apple", "playtime" });
outer.Add(new List<string>() { "star", "wars", "vader" });
var assc = outer.AssocFirstOrDefault("wars");
Assert.True(assc.Count() == 3);
var assc2 = outer.AssocFirstOrDefault("poop");
Assert.True(assc2 == null);
}
[Fact]
public void TestCycle()
{
var p = new List<string> { "a", "b" };
var count = 0;
p.Cycle(a => count++, 2);
Assert.True(count == 4);
}
[Fact]
public void TestForEach()
{
var counter = 0;
Enumerable.Range(1, 4).ForEach(a => counter++);
Assert.Equal(counter, 4);
}
[Fact]
public void TestForEachIndex()
{
var counter = 0;
Enumerable.Range(1, 4).ForEach((a, index) =>
{
Assert.Equal(counter, index);
counter++;
});
Assert.Equal(counter, 4);
}
[Fact]
public void TestDistinct()
{
var items = new List<Tuple<string, string>>();
items.Add(Tuple.Create("awesom", "1"));
items.Add(Tuple.Create("awesom", "7"));
items.Add(Tuple.Create("awesom", "6"));
items.Add(Tuple.Create("awzomes", "2"));
items.Add(Tuple.Create("pwned", "3"));
items.Add(Tuple.Create("kewlbz", "4"));
var result = items.Distinct(a => a.Item1);
Assert.True(result.Count() == 4);
}
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>ac5573fd-73c9-47cd-94b8-59b562bc3e54</ProjectGuid>
<RootNamespace>LinqRb.UnitTests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LinqRb.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LinqRb.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

View File

@@ -0,0 +1,39 @@
{
"version": "1.0.0-*",
"description": "LinqRb.UnitTests Class Library",
"authors": [ "parne" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-beta6-build191",
"LinqRb": ""
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks": {
"dnx50": {
"dependencies": {
"System.Collections": "4.0.11-beta-*",
"System.Collections.Concurrent": "4.0.11-beta-*",
"System.ComponentModel": "4.0.1-beta-*",
"System.Diagnostics.Contracts": "4.0.1-beta-*",
"System.Diagnostics.Debug": "4.0.11-beta-*",
"System.Diagnostics.Tools": "4.0.1-beta-*",
"System.Globalization": "4.0.11-beta-*",
"System.Linq": "4.0.1-beta-*",
"System.Linq.Expressions": "4.0.11-beta-*",
"System.Reflection": "4.1.0-beta-*",
"System.Reflection.Extensions": "4.0.1-beta-*",
"System.Reflection.Primitives": "4.0.1-beta-*",
"System.Reflection.TypeExtensions": "4.0.1-beta-*",
"System.Resources.ResourceManager": "4.0.1-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.Threading": "4.0.11-beta-*",
"System.Threading.Tasks": "4.0.11-beta-*"
}
}
}
}

View File

@@ -0,0 +1,132 @@
using System.Collections.Generic;
namespace System.Linq
{
public static class IEnumerable
{
/// <summary>
/// Return Enumerable where action is not true
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static IEnumerable<T> Reject<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
foreach(T element in source)
{
if(!predicate(element)) yield return element;
}
}
/// <summary>
/// Returns the first array that contains the object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static IEnumerable<T> AssocFirstOrDefault<T>(this IEnumerable<IEnumerable<T>> source, T obj)
{
var outer = source.GetEnumerator();
while(outer.MoveNext())
{
var inner = outer.Current.GetEnumerator();
while(inner.MoveNext())
{
if(inner.Current.Equals(obj))
{
return outer.Current;
}
}
}
return null;
}
/// <summary>
/// Remove all nulls
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static IEnumerable<T> Compact<T>(this IEnumerable<T> source)
where T : class
{
foreach(var item in source)
{
if(item != null)
{
yield return item;
}
}
}
/// <summary>
/// Run action over array x times
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="action"></param>
/// <param name="times">Times we should enumerate over the array</param>
public static void Cycle<T>(this IEnumerable<T> source, Action<T> action, int times)
{
for(int i = 0; i < times; i++)
{
Enumerate(source, action);
}
}
/// <summary>
/// Infinate loop over Enumerable calling the action over each one
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="action"></param>
public static void Cycle<T>(this IEnumerable<T> source, Action<T> action)
{
while(true)
{
Enumerate(source, action);
}
}
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
Enumerate(source, action);
}
public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> action)
{
var index = 0;
var enumerator = source.GetEnumerator();
while(enumerator.MoveNext())
{
action?.Invoke(enumerator.Current, index);
index++;
}
}
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> source, Func<T, object> comparer)
{
var items = new HashSet<object>();
foreach(var item in source)
{
var comparedItem = comparer?.Invoke(item);
if(!items.Contains(comparedItem))
{
items.Add(comparedItem);
yield return item;
}
}
}
private static void Enumerate<T>(IEnumerable<T> source, Action<T> action)
{
var enumerator = source.GetEnumerator();
while(enumerator.MoveNext())
{
action?.Invoke(enumerator.Current);
}
}
}
}

20
src/LinqRb/LinqRb.xproj Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>1538ff9b-de9c-4ea5-95a5-912f016a04da</ProjectGuid>
<RootNamespace>LinqRb</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LinqRb")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LinqRb")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

29
src/LinqRb/project.json Normal file
View File

@@ -0,0 +1,29 @@
{
"version": "1.0.0-*",
"description": "Add additional Linq extensions familiar to ruby ppl",
"authors": [ "Tommy Parnell" ],
"tags": [ "Linq" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"dnx451": { },
"dnx452": { },
"dnx45": { },
"dnx46": { },
"dnx40": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23409"
}
},
"dotnet": {
"dependencies": {
"System.Collections": "4.0.11-beta-*",
"System.Linq": "4.0.1-beta-*",
"System.Runtime": "4.0.21-beta-*",
"System.Threading": "4.0.11-beta-*"
}
}
}
}