├── MapFilterReduceCSharp ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── MapFilterReduceCSharp.csproj └── Program.cs ├── MapFilterReduceFSharp ├── App.config ├── AssemblyInfo.fs ├── Program.fs └── MapFilterReduceFSharp.fsproj ├── MapFilterReduce.sln └── .gitignore /MapFilterReduceCSharp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MapFilterReduceFSharp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MapFilterReduce.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MapFilterReduceFSharp", "MapFilterReduceFSharp\MapFilterReduceFSharp.fsproj", "{7B93764F-917A-4F69-805F-293C92BAA48F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapFilterReduceCSharp", "MapFilterReduceCSharp\MapFilterReduceCSharp.csproj", "{79C0BB93-94DB-4F10-BFED-78324C949400}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7B93764F-917A-4F69-805F-293C92BAA48F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {7B93764F-917A-4F69-805F-293C92BAA48F}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {7B93764F-917A-4F69-805F-293C92BAA48F}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {7B93764F-917A-4F69-805F-293C92BAA48F}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {79C0BB93-94DB-4F10-BFED-78324C949400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {79C0BB93-94DB-4F10-BFED-78324C949400}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {79C0BB93-94DB-4F10-BFED-78324C949400}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {79C0BB93-94DB-4F10-BFED-78324C949400}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /MapFilterReduceCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // La información general de un ensamblado se controla mediante el siguiente 6 | // conjunto de atributos. Cambie estos valores de atributo para modificar la información 7 | // asociada con un ensamblado. 8 | [assembly: AssemblyTitle("MapFilterReduce")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MapFilterReduce")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles 18 | // para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde 19 | // COM, establezca el atributo ComVisible en true en este tipo. 20 | [assembly: ComVisible(false)] 21 | 22 | // El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. 23 | [assembly: Guid("79c0bb93-94db-4f10-bfed-78324c949400")] 24 | 25 | // La información de versión de un ensamblado consta de los cuatro valores siguientes: 26 | // 27 | // Versión principal 28 | // Versión secundaria 29 | // Número de compilación 30 | // Revisión 31 | // 32 | // Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión 33 | // mediante el carácter '*', como se muestra a continuación: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /MapFilterReduceFSharp/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | namespace MapFilterReduceFSharp.AssemblyInfo 2 | 3 | open System.Reflection 4 | open System.Runtime.CompilerServices 5 | open System.Runtime.InteropServices 6 | 7 | // La información general de un ensamblado se controla mediante el siguiente 8 | // conjunto de atributos. Cambie estos valores de atributo para modificar la información 9 | // asociada con un ensamblado. 10 | [] 11 | [] 12 | [] 13 | [] 14 | [] 15 | [] 16 | [] 17 | [] 18 | 19 | // Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles 20 | // para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde 21 | // COM, establezca el atributo ComVisible en true en este tipo. 22 | [] 23 | 24 | // El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. 25 | [] 26 | 27 | // La información de versión de un ensamblado consta de los cuatro valores siguientes: 28 | // 29 | // Versión principal 30 | // Versión secundaria 31 | // Número de compilación 32 | // Revisión 33 | // 34 | // Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión 35 | // mediante el carácter '*', como se muestra a continuación: 36 | // [] 37 | [] 38 | [] 39 | 40 | do 41 | () -------------------------------------------------------------------------------- /MapFilterReduceCSharp/MapFilterReduceCSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {79C0BB93-94DB-4F10-BFED-78324C949400} 8 | Exe 9 | Properties 10 | MapFilterReduce 11 | MapFilterReduce 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 60 | -------------------------------------------------------------------------------- /MapFilterReduceCSharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MapFilterReduce 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | // Map 14 | // El arreglo que queremos transformar 15 | var array = new List { 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 16 | 17 | //var squaredArray = SquareArray(array); // [4, 9, 16, 25, 36, 49, 64, 81, 100] 18 | 19 | var squaredArray = array.Select(x => x * x).ToArray(); 20 | 21 | // Filter 22 | // El arreglo que queremos filtrar 23 | var images = new List { 24 | "hello.jpg", 25 | "world.jpg", 26 | "hola.png", 27 | "mundo.png", 28 | "cats.jpg", 29 | "dogs.png" 30 | }; 31 | 32 | //var jpgImages = GetJpgImages(images); 33 | 34 | var jpgImages = images.Where(image => image.EndsWith(".jpg")).ToList(); // ["hello.jpg", "world.jpg", "cats.jpg"] 35 | 36 | // Reduce 37 | // 38 | 39 | //var arraySum = Sum(array); // 54 40 | 41 | var arraySum = array.Aggregate((acc, x) => acc + x); 42 | 43 | // Combinación 44 | // Vamos a definir varios ejemplos de ciudades, y meterlos en un arreglo 45 | var paris = new City { Name = "Paris", Population = 2243 }; 46 | var madrid = new City { Name = "Madrid", Population = 3216 }; 47 | var amsterdam = new City { Name = "Amsterdam", Population = 811 }; 48 | var berlin = new City { Name = "Berlin", Population = 3397 }; 49 | 50 | var cities = new City[] { paris, madrid, amsterdam, berlin }; 51 | 52 | var citiesFilter = cities.Where(city => city.Population > 1000) 53 | .Select(Scale) 54 | .Aggregate("City population", 55 | (result, c) => { 56 | return result + $"\n{c.Name}: {c.Population}";}); 57 | 58 | Console.WriteLine(citiesFilter); 59 | 60 | Console.Read(); 61 | } 62 | 63 | // Creamos la función que modificará los elementos 64 | // del arreglo elevándolo al cuadrado 65 | static List SquareArray(List arr) 66 | { 67 | var result = new List(); 68 | 69 | foreach (var x in arr) 70 | { 71 | result.Add(x * x); 72 | } 73 | 74 | return result.ToList(); 75 | } 76 | 77 | public static List GetJpgImages(List images) 78 | { 79 | var results = new List(); 80 | 81 | foreach (var image in images) 82 | { 83 | if (image.EndsWith(".jpg")) 84 | { 85 | results.Add(image); 86 | } 87 | } 88 | 89 | return results; 90 | } 91 | 92 | public static int Sum(List arr) 93 | { 94 | var acc = 0; 95 | 96 | foreach (var value in arr) 97 | { 98 | acc += value; 99 | } 100 | 101 | return acc; 102 | } 103 | 104 | 105 | // Suponiendo que tenemos la siguiente estructura de ciudades 106 | struct City 107 | { 108 | public string Name; 109 | public int Population; 110 | } 111 | 112 | 113 | // Como tenemos las ciudades con poca población, vamos a escribir una función 114 | // que nos ayude a escalar la población 115 | static City Scale(City city) 116 | { 117 | return new City { Name = city.Name, Population = city.Population * 1000 }; 118 | } 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /MapFilterReduceFSharp/Program.fs: -------------------------------------------------------------------------------- 1 | open System.Collections.Generic 2 | open System.Linq 3 | 4 | let squareArray arr = 5 | let result = new List() 6 | for x in arr do 7 | result.Add(x * x) 8 | result.ToArray() 9 | 10 | let getJpgImages images : string array = 11 | let result = new List() 12 | for x : string in images do 13 | if (x.EndsWith(".jpg")) then result.Add(x) 14 | result.ToArray() 15 | 16 | let sum arr : int = 17 | let mutable result : int = 0 18 | for x in arr do 19 | result <- result + x 20 | result 21 | 22 | // Suponiendo que tenemos la siguiente estructura de ciudades 23 | type City = 24 | struct 25 | val Name : string 26 | val Population : int 27 | new(name : string, population : int) = 28 | { Population = population 29 | Name = name } 30 | end 31 | 32 | // Como tenemos las ciudades con poca población, vamos a escribir una función 33 | // que nos ayude a escalar la población 34 | let scale(city : City ) : City = 35 | new City ( city.Name, city.Population * 1000) 36 | 37 | [] 38 | let main argv = 39 | 40 | System.Console.WriteLine("Map"); 41 | // Map 42 | // El arreglo que queremos transformar 43 | let array = [| 2; 3; 4; 5; 6; 7; 8; 9; 10 |] 44 | //let squaredArray = squareArray array // [4, 9, 16, 25, 36, 49, 64, 81, 100] 45 | let squaredArray = 46 | array 47 | |> Array.map(fun x -> x * x) // [4, 9, 16, 25, 36, 49, 64, 81, 100] 48 | 49 | for n in squaredArray do 50 | System.Console.Write(n.ToString() + " ") 51 | 52 | 53 | System.Console.WriteLine("\nFilter"); 54 | // Filter 55 | // El arreglo que queremos filtrar 56 | let images = [| 57 | "hello.jpg" 58 | "world.jpg" 59 | "hola.png" 60 | "mundo.png" 61 | "cats.jpg" 62 | "dogs.png" |] 63 | //let jpgImages = getJpgImages images // ["hello.jpg", "world.jpg", "cats.jpg"] 64 | let jpgImages = 65 | images 66 | |> Array.filter(fun image -> image.EndsWith(".jpg")) // ["hello.jpg", "world.jpg", "cats.jpg"] 67 | 68 | for images in jpgImages do 69 | System.Console.Write(images + " ") 70 | 71 | System.Console.WriteLine("\nReduce"); 72 | // Reduce 73 | //let arraySum = sum(array); // 54 74 | 75 | let arraySum = 76 | array 77 | |> Array.reduce(fun acc x -> acc + x) // 54 78 | 79 | System.Console.Write(arraySum) 80 | 81 | System.Console.WriteLine("\nCombinación"); 82 | // Combinación 83 | // Vamos a definir varios ejemplos de ciudades, y meterlos en un arreglo 84 | let paris = new City("Paris", 2243) 85 | let madrid = new City("Madrid", 3216) 86 | let amsterdam = new City("Amsterdam", 811) 87 | let berlin = new City("Berlin", 3397) 88 | 89 | let cities = [|paris;madrid;amsterdam;berlin|] 90 | 91 | let citiesFilter = 92 | cities 93 | |> Array.filter(fun city -> city.Population > 1000) 94 | |> Array.map(scale) 95 | |> Array.fold(fun result c -> result + sprintf "\n%s: %d" c.Name c.Population ) "City population" 96 | 97 | System.Console.WriteLine(citiesFilter) 98 | 99 | System.Console.ReadKey() |> ignore 100 | 101 | 0 // devolver un código de salida entero 102 | -------------------------------------------------------------------------------- /MapFilterReduceFSharp/MapFilterReduceFSharp.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 2.0 8 | 7b93764f-917a-4f69-805f-293c92baa48f 9 | Exe 10 | MapFilterReduceFSharp 11 | MapFilterReduceFSharp 12 | v4.5.2 13 | true 14 | 4.4.0.0 15 | MapFilterReduceFSharp 16 | 17 | 18 | true 19 | full 20 | false 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | 3 25 | AnyCPU 26 | bin\Debug\MapFilterReduceFSharp.XML 27 | true 28 | 29 | 30 | pdbonly 31 | true 32 | true 33 | bin\Release\ 34 | TRACE 35 | 3 36 | AnyCPU 37 | bin\Release\MapFilterReduceFSharp.XML 38 | true 39 | 40 | 41 | 42 | 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 11 56 | 57 | 58 | 59 | 60 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 61 | 62 | 63 | 64 | 65 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 66 | 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/visualstudio,windows 3 | 4 | ### Windows ### 5 | # Windows image file caches 6 | Thumbs.db 7 | ehthumbs.db 8 | 9 | # Folder config file 10 | Desktop.ini 11 | 12 | # Recycle Bin used on file shares 13 | $RECYCLE.BIN/ 14 | 15 | # Windows Installer files 16 | *.cab 17 | *.msi 18 | *.msm 19 | *.msp 20 | 21 | # Windows shortcuts 22 | *.lnk 23 | 24 | 25 | ### VisualStudio ### 26 | ## Ignore Visual Studio temporary files, build results, and 27 | ## files generated by popular Visual Studio add-ons. 28 | 29 | # User-specific files 30 | *.suo 31 | *.user 32 | *.userosscache 33 | *.sln.docstates 34 | 35 | # User-specific files (MonoDevelop/Xamarin Studio) 36 | *.userprefs 37 | 38 | # Build results 39 | [Dd]ebug/ 40 | [Dd]ebugPublic/ 41 | [Rr]elease/ 42 | [Rr]eleases/ 43 | x64/ 44 | x86/ 45 | bld/ 46 | [Bb]in/ 47 | [Oo]bj/ 48 | [Ll]og/ 49 | 50 | # Visual Studio 2015 cache/options directory 51 | .vs/ 52 | # Uncomment if you have tasks that create the project's static files in wwwroot 53 | #wwwroot/ 54 | 55 | # MSTest test Results 56 | [Tt]est[Rr]esult*/ 57 | [Bb]uild[Ll]og.* 58 | 59 | # NUNIT 60 | *.VisualState.xml 61 | TestResult.xml 62 | 63 | # Build Results of an ATL Project 64 | [Dd]ebugPS/ 65 | [Rr]eleasePS/ 66 | dlldata.c 67 | 68 | # DNX 69 | project.lock.json 70 | project.fragment.lock.json 71 | artifacts/ 72 | 73 | *_i.c 74 | *_p.c 75 | *_i.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.pch 80 | *.pdb 81 | *.pgc 82 | *.pgd 83 | *.rsp 84 | *.sbr 85 | *.tlb 86 | *.tli 87 | *.tlh 88 | *.tmp 89 | *.tmp_proj 90 | *.log 91 | *.vspscc 92 | *.vssscc 93 | .builds 94 | *.pidb 95 | *.svclog 96 | *.scc 97 | 98 | # Chutzpah Test files 99 | _Chutzpah* 100 | 101 | # Visual C++ cache files 102 | ipch/ 103 | *.aps 104 | *.ncb 105 | *.opendb 106 | *.opensdf 107 | *.sdf 108 | *.cachefile 109 | *.VC.db 110 | *.VC.VC.opendb 111 | 112 | # Visual Studio profiler 113 | *.psess 114 | *.vsp 115 | *.vspx 116 | *.sap 117 | 118 | # TFS 2012 Local Workspace 119 | $tf/ 120 | 121 | # Guidance Automation Toolkit 122 | *.gpState 123 | 124 | # ReSharper is a .NET coding add-in 125 | _ReSharper*/ 126 | *.[Rr]e[Ss]harper 127 | *.DotSettings.user 128 | 129 | # JustCode is a .NET coding add-in 130 | .JustCode 131 | 132 | # TeamCity is a build add-in 133 | _TeamCity* 134 | 135 | # DotCover is a Code Coverage Tool 136 | *.dotCover 137 | 138 | # NCrunch 139 | _NCrunch_* 140 | .*crunch*.local.xml 141 | nCrunchTemp_* 142 | 143 | # MightyMoose 144 | *.mm.* 145 | AutoTest.Net/ 146 | 147 | # Web workbench (sass) 148 | .sass-cache/ 149 | 150 | # Installshield output folder 151 | [Ee]xpress/ 152 | 153 | # DocProject is a documentation generator add-in 154 | DocProject/buildhelp/ 155 | DocProject/Help/*.HxT 156 | DocProject/Help/*.HxC 157 | DocProject/Help/*.hhc 158 | DocProject/Help/*.hhk 159 | DocProject/Help/*.hhp 160 | DocProject/Help/Html2 161 | DocProject/Help/html 162 | 163 | # Click-Once directory 164 | publish/ 165 | 166 | # Publish Web Output 167 | *.[Pp]ublish.xml 168 | *.azurePubxml 169 | # TODO: Comment the next line if you want to checkin your web deploy settings 170 | # but database connection strings (with potential passwords) will be unencrypted 171 | *.pubxml 172 | *.publishproj 173 | 174 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 175 | # checkin your Azure Web App publish settings, but sensitive information contained 176 | # in these scripts will be unencrypted 177 | PublishScripts/ 178 | 179 | # NuGet Packages 180 | *.nupkg 181 | # The packages folder can be ignored because of Package Restore 182 | **/packages/* 183 | # except build/, which is used as an MSBuild target. 184 | !**/packages/build/ 185 | # Uncomment if necessary however generally it will be regenerated when needed 186 | #!**/packages/repositories.config 187 | # NuGet v3's project.json files produces more ignoreable files 188 | *.nuget.props 189 | *.nuget.targets 190 | 191 | # Microsoft Azure Build Output 192 | csx/ 193 | *.build.csdef 194 | 195 | # Microsoft Azure Emulator 196 | ecf/ 197 | rcf/ 198 | 199 | # Windows Store app package directories and files 200 | AppPackages/ 201 | BundleArtifacts/ 202 | Package.StoreAssociation.xml 203 | _pkginfo.txt 204 | 205 | # Visual Studio cache files 206 | # files ending in .cache can be ignored 207 | *.[Cc]ache 208 | # but keep track of directories ending in .cache 209 | !*.[Cc]ache/ 210 | 211 | # Others 212 | ClientBin/ 213 | ~$* 214 | *~ 215 | *.dbmdl 216 | *.dbproj.schemaview 217 | *.pfx 218 | *.publishsettings 219 | node_modules/ 220 | orleans.codegen.cs 221 | 222 | # Since there are multiple workflows, uncomment next line to ignore bower_components 223 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 224 | #bower_components/ 225 | 226 | # RIA/Silverlight projects 227 | Generated_Code/ 228 | 229 | # Backup & report files from converting an old project file 230 | # to a newer Visual Studio version. Backup files are not needed, 231 | # because we have git ;-) 232 | _UpgradeReport_Files/ 233 | Backup*/ 234 | UpgradeLog*.XML 235 | UpgradeLog*.htm 236 | 237 | # SQL Server files 238 | *.mdf 239 | *.ldf 240 | 241 | # Business Intelligence projects 242 | *.rdl.data 243 | *.bim.layout 244 | *.bim_*.settings 245 | 246 | # Microsoft Fakes 247 | FakesAssemblies/ 248 | 249 | # GhostDoc plugin setting file 250 | *.GhostDoc.xml 251 | 252 | # Node.js Tools for Visual Studio 253 | .ntvs_analysis.dat 254 | 255 | # Visual Studio 6 build log 256 | *.plg 257 | 258 | # Visual Studio 6 workspace options file 259 | *.opt 260 | 261 | # Visual Studio LightSwitch build output 262 | **/*.HTMLClient/GeneratedArtifacts 263 | **/*.DesktopClient/GeneratedArtifacts 264 | **/*.DesktopClient/ModelManifest.xml 265 | **/*.Server/GeneratedArtifacts 266 | **/*.Server/ModelManifest.xml 267 | _Pvt_Extensions 268 | 269 | # Paket dependency manager 270 | .paket/paket.exe 271 | paket-files/ 272 | 273 | # FAKE - F# Make 274 | .fake/ 275 | 276 | # JetBrains Rider 277 | .idea/ 278 | *.sln.iml --------------------------------------------------------------------------------