commit 947c650ad0c8e1c1eb97ef579b711fcf45d1367a Author: Tommy Parnell Date: Sat Oct 24 20:38:43 2015 -0400 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ce22ce --- /dev/null +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/LinqRb.sln b/LinqRb.sln new file mode 100644 index 0000000..2bdd8b3 --- /dev/null +++ b/LinqRb.sln @@ -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 diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..95143bd --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..905c4e4 --- /dev/null +++ b/appveyor.yml @@ -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 \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..0c71551 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "projects": [ "src", "test" ], + "sdk": { + "version": "1.0.0-beta8" + } +} diff --git a/src/LinqRb.UnitTests/EnumerableTest.cs b/src/LinqRb.UnitTests/EnumerableTest.cs new file mode 100644 index 0000000..46073a9 --- /dev/null +++ b/src/LinqRb.UnitTests/EnumerableTest.cs @@ -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>(); + outer.Add(new List() { "books", "school", "apple", "playtime" }); + outer.Add(new List() { "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 { "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>(); + 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); + } + } +} \ No newline at end of file diff --git a/src/LinqRb.UnitTests/LinqRb.UnitTests.xproj b/src/LinqRb.UnitTests/LinqRb.UnitTests.xproj new file mode 100644 index 0000000..be407e4 --- /dev/null +++ b/src/LinqRb.UnitTests/LinqRb.UnitTests.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + ac5573fd-73c9-47cd-94b8-59b562bc3e54 + LinqRb.UnitTests + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + + + + \ No newline at end of file diff --git a/src/LinqRb.UnitTests/Properties/AssemblyInfo.cs b/src/LinqRb.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c85cd8b --- /dev/null +++ b/src/LinqRb.UnitTests/Properties/AssemblyInfo.cs @@ -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)] \ No newline at end of file diff --git a/src/LinqRb.UnitTests/project.json b/src/LinqRb.UnitTests/project.json new file mode 100644 index 0000000..6eb7b04 --- /dev/null +++ b/src/LinqRb.UnitTests/project.json @@ -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-*" + } + } + } +} \ No newline at end of file diff --git a/src/LinqRb/Extensions/IEnumerable.cs b/src/LinqRb/Extensions/IEnumerable.cs new file mode 100644 index 0000000..b33114f --- /dev/null +++ b/src/LinqRb/Extensions/IEnumerable.cs @@ -0,0 +1,132 @@ +using System.Collections.Generic; + +namespace System.Linq +{ + public static class IEnumerable + { + /// + /// Return Enumerable where action is not true + /// + /// + /// + /// + /// + public static IEnumerable Reject(this IEnumerable source, Func predicate) + { + foreach(T element in source) + { + if(!predicate(element)) yield return element; + } + } + + /// + /// Returns the first array that contains the object + /// + /// + /// + /// + /// + public static IEnumerable AssocFirstOrDefault(this IEnumerable> 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; + } + + /// + /// Remove all nulls + /// + /// + /// + /// + public static IEnumerable Compact(this IEnumerable source) + where T : class + { + foreach(var item in source) + { + if(item != null) + { + yield return item; + } + } + } + + /// + /// Run action over array x times + /// + /// + /// + /// + /// Times we should enumerate over the array + public static void Cycle(this IEnumerable source, Action action, int times) + { + for(int i = 0; i < times; i++) + { + Enumerate(source, action); + } + } + + /// + /// Infinate loop over Enumerable calling the action over each one + /// + /// + /// + /// + public static void Cycle(this IEnumerable source, Action action) + { + while(true) + { + Enumerate(source, action); + } + } + + public static void ForEach(this IEnumerable source, Action action) + { + Enumerate(source, action); + } + + public static void ForEach(this IEnumerable source, Action action) + { + var index = 0; + var enumerator = source.GetEnumerator(); + while(enumerator.MoveNext()) + { + action?.Invoke(enumerator.Current, index); + index++; + } + } + + public static IEnumerable Distinct(this IEnumerable source, Func comparer) + { + var items = new HashSet(); + foreach(var item in source) + { + var comparedItem = comparer?.Invoke(item); + if(!items.Contains(comparedItem)) + { + items.Add(comparedItem); + yield return item; + } + } + } + + private static void Enumerate(IEnumerable source, Action action) + { + var enumerator = source.GetEnumerator(); + while(enumerator.MoveNext()) + { + action?.Invoke(enumerator.Current); + } + } + } +} \ No newline at end of file diff --git a/src/LinqRb/LinqRb.xproj b/src/LinqRb/LinqRb.xproj new file mode 100644 index 0000000..133cd39 --- /dev/null +++ b/src/LinqRb/LinqRb.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 1538ff9b-de9c-4ea5-95a5-912f016a04da + LinqRb + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/LinqRb/Properties/AssemblyInfo.cs b/src/LinqRb/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7910e03 --- /dev/null +++ b/src/LinqRb/Properties/AssemblyInfo.cs @@ -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)] \ No newline at end of file diff --git a/src/LinqRb/project.json b/src/LinqRb/project.json new file mode 100644 index 0000000..8dbb92e --- /dev/null +++ b/src/LinqRb/project.json @@ -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-*" + } + } + } +} \ No newline at end of file