diff --git a/_snippets/helloworld.md b/_snippets/0 helloworld.md similarity index 100% rename from _snippets/helloworld.md rename to _snippets/0 helloworld.md diff --git a/_snippets/oop.md b/_snippets/10 oop.md similarity index 95% rename from _snippets/oop.md rename to _snippets/10 oop.md index be1ec08c..b9feb58e 100644 --- a/_snippets/oop.md +++ b/_snippets/10 oop.md @@ -42,7 +42,6 @@ code: | F# is **functional first** and **immutable by default**, but it also provides pragmatic support for object programming. -- **Seamless .NET integration** lets you work with existing .NET libraries and frameworks - **Rich interface system** allows you to define clear contracts for your components - **Object expressions** provide lightweight implementation of interfaces without defining full classes - **Concise member syntax** keeps methods and properties clean and readable diff --git a/_snippets/domain_modelling.md b/_snippets/11 domain modelling.md similarity index 100% rename from _snippets/domain_modelling.md rename to _snippets/11 domain modelling.md diff --git a/_snippets/sequence_expressions.md b/_snippets/12 sequence expressions.md similarity index 81% rename from _snippets/sequence_expressions.md rename to _snippets/12 sequence expressions.md index 90916d95..4815e073 100644 --- a/_snippets/sequence_expressions.md +++ b/_snippets/12 sequence expressions.md @@ -1,14 +1,13 @@ --- -order: 15 +order: 12 title: SequenceExpressions.fs excerpt_separator: code: | let rec fizzBuzzSeq n = seq { - match n with - | x when x % 15 = 0 -> "fizzbuzz" - | x when x % 3 = 0 -> "fizz" - | x when x % 5 = 0 -> "buzz" - | _ -> n.ToString() + if n % 15 = 0 then "fizzbuzz" + elif n % 3 = 0 then "fizz" + elif n % 5 = 0 then "buzz" + else n.ToString() // Tail recursion makes this as efficient as a "while" loop yield! fizzBuzzSeq (n + 1) diff --git a/_snippets/async_expressions.md b/_snippets/13 async expressions.md similarity index 95% rename from _snippets/async_expressions.md rename to _snippets/13 async expressions.md index c14854d6..980ec66e 100644 --- a/_snippets/async_expressions.md +++ b/_snippets/13 async expressions.md @@ -1,5 +1,5 @@ --- -order: 16 +order: 13 title: AsyncExpressions.fs excerpt_separator: code: | @@ -20,7 +20,7 @@ code: | return $"Validation error: {msg}" } - processPersonAsync { Name = "Snowdrop"; Age = 13} + processPersonAsync { Name = "Snowdrop"; Age = 13 } |> Async.RunSynchronously --- ## Async Programming made Easy diff --git a/_snippets/computation_expressions.md b/_snippets/14 computation expressions.md similarity index 99% rename from _snippets/computation_expressions.md rename to _snippets/14 computation expressions.md index 42a728c2..4cc5ebe5 100644 --- a/_snippets/computation_expressions.md +++ b/_snippets/14 computation expressions.md @@ -1,5 +1,5 @@ --- -order: 17 +order: 14 title: ComputationExpressions.fs excerpt_separator: code: | diff --git a/_snippets/unitsOfMeasure.md b/_snippets/15 units of measure.md similarity index 99% rename from _snippets/unitsOfMeasure.md rename to _snippets/15 units of measure.md index f305985c..c241b3f1 100644 --- a/_snippets/unitsOfMeasure.md +++ b/_snippets/15 units of measure.md @@ -1,5 +1,5 @@ --- -order: 19 +order: 15 title: UnitsOfMeasure.fs excerpt_separator: code: | diff --git a/_snippets/typeproviders.md b/_snippets/16 type providers.md similarity index 86% rename from _snippets/typeproviders.md rename to _snippets/16 type providers.md index b48e2674..bec73076 100644 --- a/_snippets/typeproviders.md +++ b/_snippets/16 type providers.md @@ -1,9 +1,9 @@ --- -order: 14 +order: 16 title: TypeProviders.fs excerpt_separator: code: | - open FSharp.Data + open FSharp.Data // dotnet package add FSharp.Data type PeopleDB = CsvProvider<"people.csv"> @@ -12,7 +12,7 @@ code: | for person in people.Rows do // Access the CSV fields with intellisense and type safety! - printfn $"Name: %s{person.Name}, Id: %i{person.Id}" + printfn $"Name: {person.Name: string}, Id: {person.Id: int}" --- ## Type-Safe, Integrated Data diff --git a/_snippets/21 ecosystems.md b/_snippets/21 ecosystems.md new file mode 100644 index 00000000..e56ac31c --- /dev/null +++ b/_snippets/21 ecosystems.md @@ -0,0 +1,45 @@ +--- +order: 21 +title: Ecosystems.fs +excerpt_separator: +code: | + // JavaScript Example: Image processing + open Fable.Core + open Fable.Core.JS + // Read documentation, then define the JavaScript type + type [] Image = // npm install image-js + static member load(path: string): Promise = jsNative + member _.flipX(): Image = jsNative + member _.flipY(): Image = jsNative + [] member _.resize(?width: float, ?height: float): Image = jsNative + member _.save(path: string): Promise = jsNative + promise { + let! image = Image.load "input.png" + let image = image.resize(width=300, height=200).flipX().flipY() + do! image.save "output.jpg" + } |> _.catch(fun x -> console.error x) |> ignore + + // .NET Example: Image processing + // C# types have seamless integration with F#. + open SixLabors.ImageSharp // dotnet package add SixLabors.ImageSharp + open SixLabors.ImageSharp.Processing + use image = Image.Load "input.png" + image.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore) + image.Save "output.jpg" + + // Code sharing Example: The same code works across JavaScript and .NET + open System.Text.RegularExpressions // Specific System types are usable anywhere. + let input = "Emails: user1@test.com, user2@domain.org, invalid-email" + let pattern = @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b" + for matched in Regex.Matches(input, pattern) do + printfn $"Found email: {matched.Value}" // user1@test.com and user2@domain.org +--- +## Full access to ecosystems of libraries + +F# has full integration with ecosystems of JavaScript and .NET libraries and frameworks. +Anything written in JavaScript or C# can be used from F# and vice versa. + +- **JavaScript** is the universal language of web development. It encompasses [Web](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Mobile](https://reactnative.dev/), [Desktop](https://www.electronjs.org/), [Cloud](https://nodejs.org/), [Microservices](https://nestjs.com/), [Artificial Intelligence](https://www.tensorflow.org/js), [Game Development](https://phaser.io/) and [Internet of Things](https://johnny-five.io/). +- **.NET** is Microsoft’s enterprise-grade platform for scalable applications. It also encompasses **[Web](https://dotnet.microsoft.com/en-us/apps/aspnet), [Mobile](https://dotnet.microsoft.com/en-us/apps/maui), [Desktop](https://dotnet.microsoft.com/en-us/apps/desktop), [Cloud](https://dotnet.microsoft.com/en-us/apps/cloud), [Microservices](https://dotnet.microsoft.com/en-us/apps/aspnet/microservices), [Artificial Intelligence](https://dotnet.microsoft.com/en-us/apps/ai), [Game Development](https://dotnet.microsoft.com/en-us/apps/games), and [Internet of Things](https://dotnet.microsoft.com/en-us/apps/iot)**. +- [**npm packages**](https://www.npmjs.com/package/image-js) or [**NuGet packages**](https://www.nuget.org) can be accessed from F#, reusing existing packages to suit your needs. +- **Incremental adoption** is possbile by mixing Javascript or C# with F#. diff --git a/_snippets/fable.md b/_snippets/22 fable.md similarity index 87% rename from _snippets/fable.md rename to _snippets/22 fable.md index 447dfb30..d6597b08 100644 --- a/_snippets/fable.md +++ b/_snippets/22 fable.md @@ -1,5 +1,5 @@ --- -order: 12 +order: 22 title: WebApps.fs excerpt_separator: code: | @@ -32,7 +32,8 @@ code: | --- ## F# for JavaScript and the Full Stack -F# is for both client and server. With [F# web technologies]({{ '/use/web-apps/' | relative_url }}), you can target JavaScript environments directly. This means you can use F# to build web applications, mobile apps, and even serverless functions that run in the cloud. +F# is for both client and server. With [F# web technologies]({{ '/use/web-apps/' | relative_url }}), you can target JavaScript environments directly without including the rest of .NET. +This means you can use F# across both frontend and backend to build web applications, mobile apps, and even serverless functions that run in the cloud. - **Type-safe DOM manipulation** catches errors at compile time, not runtime - **Seamless React integration** with hooks and modern patterns diff --git a/_snippets/ecosystem.md b/_snippets/ecosystem.md new file mode 100644 index 00000000..3b4c679b --- /dev/null +++ b/_snippets/ecosystem.md @@ -0,0 +1,46 @@ +--- +order: 1 +title: DotNet.fs +excerpt_separator: +code: | + // JavaScript Example: Image processing + open Fable.Core + open Fable.Core.JS + // Read documentation, then define the JavaScript type + type [] Image = // npm install image-js + static member load(path: string): Promise = jsNative + member _.flipX(): Image = jsNative + member _.flipY(): Image = jsNative + [] member _.resize(?width: float, ?height: float): Image = jsNative + member _.save(path: string): Promise = jsNative + (promise { + let! image = Image.load "input.png" + let image = image.resize(width=300, height=200).flipX().flipY() + do! image.save "output.jpg" + }).catch(fun x -> console.error x) |> ignore + + // .NET Example: Image processing + // C# types have seamless integration with F#. + open SixLabors.ImageSharp // dotnet package add SixLabors.ImageSharp + open SixLabors.ImageSharp.Processing + use image = Image.Load "input.png" // .NET types are integrated seamlessly. + image.Mutate(_.Resize(300, 200).Flip(FlipMode.Horizontal ||| FlipMode.Vertical) >> ignore) + image.Save "output.jpg" + + // Code sharing Example: The same code works across JavaScript and .NET + open System.Text.RegularExpressions // Specific System types are usable anywhere. + let input = "Emails: user1@test.com, user2@domain.org, invalid-email" + let pattern = @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b" + for matched in Regex.Matches(input, pattern) do + printfn $"Found email: {matched.Value}" // user1@test.com and user2@domain.org + --- + +## Full access to ecosystems of libraries + +F# has full integration with ecosystems of JavaScript and Microsoft .NET libraries and frameworks. +Anything written in JavaScript or C# can be used from F# and vice versa. + +- **JavaScript** is the universal language of web development. It encompasses [Web](https://developer.mozilla.org/en-US/docs/Web/JavaScript), [Mobile](https://reactnative.dev/), [Desktop](https://www.electronjs.org/), [Cloud](https://nodejs.org/), [Microservices](https://nestjs.com/), [Artificial Intelligence](https://www.tensorflow.org/js), [Game Development](https://phaser.io/) and [Internet of Things](https://johnny-five.io/). +- **.NET** is Microsoft’s enterprise-grade platform for scalable applications. It also encompasses **[Web](https://dotnet.microsoft.com/en-us/apps/aspnet), [Mobile](https://dotnet.microsoft.com/en-us/apps/maui), [Desktop](https://dotnet.microsoft.com/en-us/apps/desktop), [Cloud](https://dotnet.microsoft.com/en-us/apps/cloud), [Microservices](https://dotnet.microsoft.com/en-us/apps/aspnet/microservices), [Artificial Intelligence](https://dotnet.microsoft.com/en-us/apps/ai), [Game Development](https://dotnet.microsoft.com/en-us/apps/games), and [Internet of Things](https://dotnet.microsoft.com/en-us/apps/iot)**. +- [**npm packages**](https://www.npmjs.com/package/image-js) or [**NuGet packages**](https://www.nuget.org) can be accessed from F#, reusing existing packages to suit your needs. +- **Incremental adoption** is possible by mixing Javascript or C# with F#.