language-ext

所属分类:collect
开发工具:C#
文件大小:0KB
下载次数:0
上传日期:2023-05-18 02:01:31
上 传 者sh-1993
说明:  C#函数语言扩展-用于函数编程的基类库,
(C# functional language extensions - a base class library for functional programming,)

文件列表:
.editorconfig (9766, 2023-11-09)
CODE_OF_CONDUCT.md (3214, 2023-11-09)
CONTRIBUTING.md (2242, 2023-11-09)
Images/ (0, 2023-11-09)
Images/banner.png (8129, 2023-11-09)
Images/discussions.svg (1172, 2023-11-09)
Images/lang-ext-small.png (5986, 2023-11-09)
Images/lang-ext-thumb.png (1548, 2023-11-09)
Images/tree1.jpg (15289, 2023-11-09)
Images/tree2.jpg (20830, 2023-11-09)
LICENSE.md (1082, 2023-11-09)
LanguageExt.Benchmarks/ (0, 2023-11-09)
LanguageExt.Benchmarks/HashMapAddBenchmarks.cs (2505, 2023-11-09)
LanguageExt.Benchmarks/HashMapContainsKeyBenchmarks.cs (3053, 2023-11-09)
LanguageExt.Benchmarks/HashMapIterateBenchmarks.cs (3143, 2023-11-09)
LanguageExt.Benchmarks/HashMapRandomRemovalBenchmarks.cs (3270, 2023-11-09)
LanguageExt.Benchmarks/HashSetAddBenchmarks.cs (2085, 2023-11-09)
LanguageExt.Benchmarks/HashSetContainsBenchmarks.cs (2579, 2023-11-09)
LanguageExt.Benchmarks/HashSetIterationBenchmarks.cs (2680, 2023-11-09)
LanguageExt.Benchmarks/HashSetRandomRemovalBenchmarks.cs (2779, 2023-11-09)
LanguageExt.Benchmarks/LanguageExt.Benchmarks.csproj (522, 2023-11-09)
LanguageExt.Benchmarks/ListAddBenchmarks.cs (1560, 2023-11-09)
LanguageExt.Benchmarks/ListIterationBenchmarks.cs (1869, 2023-11-09)
LanguageExt.Benchmarks/Program.cs (259, 2023-11-09)
LanguageExt.Benchmarks/ValuesGenerator.MapSetup.cs (2317, 2023-11-09)
LanguageExt.Benchmarks/ValuesGenerator.SetSetup.cs (1808, 2023-11-09)
LanguageExt.Benchmarks/ValuesGenerator.cs (2303, 2023-11-09)
LanguageExt.CodeGen/ (0, 2023-11-09)
LanguageExt.CodeGen/CodeGenUtil.cs (169985, 2023-11-09)
LanguageExt.CodeGen/FreeAttribute.cs (687, 2023-11-09)
LanguageExt.CodeGen/FreeGenerator.cs (88889, 2023-11-09)
LanguageExt.CodeGen/LanguageExt.CodeGen.csproj (2090, 2023-11-09)
LanguageExt.CodeGen/RWSAttribute.cs (1573, 2023-11-09)
LanguageExt.CodeGen/RWSGenerator.cs (159418, 2023-11-09)
LanguageExt.CodeGen/ReaderAttribute.cs (840, 2023-11-09)
LanguageExt.CodeGen/ReaderGenerator.cs (87182, 2023-11-09)
... ...

![lang-ext](https://raw.githubusercontent.com/louthy/language-ext/main/Images/banner.png) C# Functional Programming Language Extensions ============================================= This library uses and abuses the features of C# to provide a functional-programming 'base class library' that, if you squint, can look like extensions to the language itself. The desire here is to make programming in C# much more reliable and to make the engineer's inertia flow in the direction of declarative and functional code rather than imperative. [![GitHub Discussions](https://raw.githubusercontent.com/louthy/language-ext/main/Images/discussions.svg)](https://github.com/louthy/language-ext/discussions) __Author on...__ * __twitter:__ [@paullouth](https://twitter.com/paullouth) * __mastodon:__ [@louthy@4four.org](https://4four.org/@louthy) __Paul Louth [discussing FP for the GitHub ReadME project](https://github.com/readme/featured/functional-programming)__ ## Contents * [Reference](#reference) * [Nu-get package](#nu-get) * [Code-gen setup](#code-gen-setup) * [Unity](#unity) * [Getting started](#getting-started) * [Prologue](#prologue) * [**Features**](#features) * [Functional effects and IO](#functional-effects-and-io) * [Atomic concurrency, shared state, and collections](#atomic-concurrency-and-collections) * [Immutable collections](#immutable-collections) * [Optional and Alternative value monads](#optional-and-alternative-value-monads) * [State managing monads](#state-managing-monads) * [Parser combinators](#parser-combinators) * [Type aliasing](#new-types---type-aliasing) * [Records, Unions, Free Monads, Lenses - Code Generation](#code-generation) * [Pretty: Produce nicely formatted text with smart layouts](#pretty) * [Make C# better: memoisation, currying, partial application, `Nullable`, `Task`, and `IQueryable` extensions](#make-c-better) * [Poor tuple support](#poor-tuple-support) * [Null reference problem](#null-reference-problem) * [Option](#option) * [Lack of lambda and expression inference](#lack-of-lambda-and-expression-inference) * [Void isn't a real type](#void-isnt-a-real-type) * [Mutable lists and dictionaries](#mutable-lists-and-dictionaries) * [Lists](#lists) * [List pattern matching](#list-pattern-matching) * [Maps](#maps) * [Difficulty in creating immutable record types](#difficulty-in-creating-immutable-record-types) * [Transformation of immutable types](#transformation-of-immutable-types) * [`[With]`](#with) * [Transformation of nested immutable types with Lenses](#transformation-of-nested-immutable-types-with-lenses) * [`[WithLens]`](#withlens) * [The awful 'out' parameter](#the-awful-out-parameter) * [The lack of ad-hoc polymorphism](#ad-hoc-polymorphism) * [`Num`](#num) * [`Eq`](#eq) * [`Ord`](#ord) * [`Semigroup`](#semigroup) * [`Monoid`](#monoid) * [`Monad`](#monad) * [Transformer types](#transformer-types) * [Contributing & Code of Conduct](#contributing--code-of-conduct) ## Reference * [API Reference](https://louthy.github.io/language-ext/) * [Issues that contain documentation and examples](https://github.com/louthy/language-ext/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22examples%20%2F%20documentation%22%20) ## Nu-get Nu-get package | Description ---------------|------------- [LanguageExt.Core](https://www.nuget.org/packages/LanguageExt.Core) | All of the core types and functional 'prelude'. __This is all that's needed to get started__. [LanguageExt.Transformers](https://www.nuget.org/packages/LanguageExt.Transformers) | For every combination of monadic type `M>` (i.e. `Seq>`), this package provides the following extension methods: `ApplyT`, `AppendT`, `BindT`, `CompareT`, `CountT`, `EqualsT`, `ExistsT`, `ForAllT`, `FoldT`, `FoldBackT`, `FilterT`, `IterT`, `MapT`, `PlusT`, `ProductT`, `SubtractT`, `DivideT`, and `SumT`. Which makes it much easier to work with those nested types (no need to manually unpack the bound values) [LanguageExt.FSharp](https://www.nuget.org/packages/LanguageExt.FSharp) | F# to C# interop package. Provides interop between the LanguageExt.Core types (like `Option`, `List` and `Map`) to the F# equivalents, as well as interop between core BCL types and F# [LanguageExt.Parsec](https://www.nuget.org/packages/LanguageExt.Parsec) | Port of the [Haskell parsec library](https://hackage.haskell.org/package/parsec) [LanguageExt.Rx](https://www.nuget.org/packages/LanguageExt.Rx) | Reactive Extensions support for various types within the Core [LanguageExt.Sys](https://www.nuget.org/packages/LanguageExt.Sys) | Provides an [`Aff` and `Eff`](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) wrapper around the .NET System namespace making common IO operations pure and unit-testable [LanguageExt.SysX](https://www.nuget.org/packages/LanguageExt.SysX) | As above, but provides .NET5+ specific features [LanguageExt.CodeGen](https://www.nuget.org/packages/LanguageExt.CodeGen) | [Used to generate records, unions, lenses, and `With` functions automagically](https://github.com/louthy/language-ext/wiki/Code-generation). ## Code-gen setup To use the code-generation features of `language-ext` (which are totally optional by the way), then you must include the [LanguageExt.CodeGen](https://www.nuget.org/packages/LanguageExt.CodeGen) package into your project. To make the reference **build and design time only** (i.e. your project doesn't gain an additional dependencies because of the code-generator), open up your `csproj` and set the `PrivateAssets` attribute to `all`: ```xml ``` > Obviously, update the `Version` attributes to the appropriate values. Also note that you will probably need the latest VS2019+ for this to work. Even early versions of VS2019 seem to have problems. There's more information on the code-gen features on [the wiki](https://github.com/louthy/language-ext/wiki/Code-generation) ## Unity This library seems compatible on the latest (at the time of writing) Unity 2018.2 with __incremental compiler__ (which enables C# 7), so it should work well once Unity has official support for C# 7 on upcoming 2018.3. In the meanwhile, you can install incremental compiler instead. If you are concerned about writing functionally and the possible performance overheads then please take a look at [this wiki page](https://github.com/louthy/language-ext/wiki/Performance). ## Getting started To use this library, simply include `LanguageExt.Core.dll` in your project or grab it from NuGet, and add this to the top of each `.cs` file that needs it: ```C# using LanguageExt; using static LanguageExt.Prelude; ``` The namespace `LanguageExt` contains the core types, and `LanguageExt.Prelude` contains the functions that you bring into scope `using static LanguageExt.Prelude`. ## Prologue One of the great features of C#6+ is that it allows us to treat static classes like namespaces. This means that we can use static methods without qualifying them first. That instantly gives us access to single term method names that look exactly like functions in functional languages. i.e. ```C# using static System.Console; WriteLine("Hello, World"); ``` This library tries to bring some of the functional world into C#. It won't always sit well with the seasoned C# OO programmer, especially the choice of camelCase names for a lot of functions and the seeming 'globalness' of a lot of the library. I can understand that much of this library is non-idiomatic, but when you think of the journey C# has been on, is "idiomatic" necessarily right? A lot of C#'s idioms are inherited from Java and C# 1.0. Since then we've had generics, closures, Func, LINQ, async... C# as a language is becoming more and more like a functional language on every release. In fact, the bulk of the new features are either inspired by or directly taken from features in functional languages. So perhaps it's time to move the C# idioms closer to the functional world's idioms? ### A note about naming One of the areas that's likely to get seasoned C# heads worked up is my choice of naming style. The intent is to try and make something that _feels_ like a functional language rather than following rules of naming conventions (mostly set out by the BCL). There is, however, a naming guide that will keep you in good stead while reading through this documentation: * Type names are `PascalCase` in the normal way * The types all have constructor functions rather than public constructors that you instantiate with `new`. They will always be `PascalCase`: ```C# Option x = Some(123); Option y = None; Seq items = Seq(1,2,3,4,5); List items = List(1,2,3,4,5); HashMap dict = HashMap((1, "Hello"), (2, "World")); Map dict = Map((1, "Hello"), (2, "World")); ``` * Any (non-type constructor) static function that can be used on its own by `using static LanguageExt.Prelude` are `camelCase`. ```C# var x = map(opt, v => v * 2); ``` * Any extension methods, or anything "fluent" are `PascalCase` in the normal way ```C# var x = opt.Map(v => v * 2); ``` Even if you disagree with this non-idiomatic approach, all of the `camelCase` static functions have fluent variants, so you never actually have to see the non-standard stuff. _If you're not using C# 6 yet, then you can still use this library. Anywhere in the docs below where you see a camelCase function it can be accessed by prefixing with `Prelude.`_ ## Features ### Functional effects and IO Location | Feature | Description ---------|---------|------------ `Core` | `Aff` | [An asynchronous effect: an IO monad](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) `Core` | `Eff` | [A synchronous effect: an IO monad](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) `Core` | `Aff` | [An asynchronous effect with injectable runtime: a unit testable IO monad](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) `Core` | `Eff` | [A synchronous effect with injectable runtime: a unit testable IO monad](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) `Core` | Pipes | [A clean and powerful stream processing system that lets you build and connect reusable streaming components](https://github.com/louthy/language-ext/wiki/How-to-deal-with-side-effects) ### Atomic concurrency and collections Location | Feature | Description ---------|---------|------------ `Core` | `Atom` | [A lock-free atomically mutable reference for working with shared state](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/Atom) `Core` | `Ref` | [An atomic reference to be used in the transactional memory system](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/STM) `Core` | `AtomHashMap` | [An immutable `HashMap` with a lock-free atomically mutable reference](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/AtomHashMap) `Core` | `AtomSeq` | [An immutable `Seq` with a lock-free atomically mutable reference](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/AtomSeq) `Core` | `VectorClock` | [Understand distributed causality](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/VectorClock) `Core` | `VersionVector` | [A vector clock with some versioned data](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/VersionVector) `Core` | `VersionHashMap ` | [Distrubuted atomic versioning of keys in a hash-map](https://louthy.github.io/language-ext/LanguageExt.Core/Concurrency/VersionHashMap) ### Immutable collections Location | Feature | Description ---------|---------|------------ `Core` | `Arr` | [Immutable array](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Arr/index.html) `Core` | `Seq` | [Immutable list with lazy behavior - a better `IEnumerable`. Very, very fast!](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Seq/index.html) `Core` | `Lst` | [Immutable list - use `Seq` over `Lst` unless you need `InsertAt`](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/List/index.html) `Core` | `Map` | [Immutable map](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Map/index.html) `Core` | `Map` | [Immutable map with Ord constraint on `K`](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Map/index.html) `Core` | `HashMap` | [Immutable hash-map](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/HashMap/index.html) `Core` | `HashMap` | [Immutable hash-map with Eq constraint on `K`](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/HashMap/index.html) `Core` | `Set` | [Immutable set](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Set/index.html) `Core` | `Set` | [Immutable set with Ord constraint on `A`](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Set/index.html) `Core` | `HashSet` | [Immutable hash-set](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/HashSet/index.html) `Core` | `HashSet` | [Immutable hash-set with Eq constraint on `A`](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/HashSet/index.html) `Core` | `Que` | [Immutable queue](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Queue/index.html) `Core` | `Stck` | [Immutable stack](https://louthy.github.io/language-ext/LanguageExt.Core/Immutable%20Collections/Stack/index.html) ### Optional and alternative value monads Location | Feature | Description ---------|---------|------------ `Core` | `Option` | [Option monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Option/Option/index.html) that can't be used with `null` values `Core` | `OptionAsync` | [OptionAsync monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Option/OptionAsync/index.html) that can't be used with `null` values with all value realisation does asynchronously `Core` | `OptionUnsafe` | [Option monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Option/OptionUnsafe/index.html) that can be used with `null` values `Core` | `Either` | [Right/Left choice monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Either/Either/index.html) that won't accept `null` values `Core` | `EitherUnsafe` | [Right/Left choice monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Either/EitherUnsafe/index.html) that can be used with `null` values `Core` | `EitherAsync` | [EitherAsync monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Either/EitherAsync/index.html) that can't be used with `null` values with all value realisation done asynchronously `Core` | `Try` | [Exception handling lazy monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Try/Try/index.html) `Core` | `TryAsync` | [Asynchronous exception handling lazy monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Try/TryAsync/index.html) `Core` | `TryOption` | [Option monad with third state](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Try/TryOption/index.html) 'Fail' that catches exceptions `Core` | `TryOptionAsync` | [Asynchronous Option monad with third state](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Try/TryOptionAsync/index.html) 'Fail' that catches exceptions `Core` | `Validation` | [Validation applicative and monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Validation/index.html) for collecting multiple errors before aborting an operation `Core` | `Validation` | [Validation applicative and monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/Alternative%20Value%20Monads/Validation/index.html) for collecting multiple errors before aborting an operation, uses the supplied monoid in the first generic argument to collect the failure values. ### State managing monads Location | Feature | Description ---------|---------|------------ `Core` | `Reader` | [Reader monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/State%20and%20Environment%20Monads/Reader/index.html) `Core` | `Writer` | [Writer monad that logs to a `W` constrained to be a Monoid](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/State%20and%20Environment%20Monads/Writer/index.html) `Core` | `State` | [State monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/State%20and%20Environment%20Monads/State/index.html) `Core` | `RWS` | [Reader Writer State monad](https://louthy.github.io/language-ext/LanguageExt.Core/Monads/State%20and%20Environment%20Monads/RWS/index.html) ### Parser combinators Location | Feature | Description ---------|---------|------------ `Parsec` | `Parser` | [String parser monad and full parser combinators library](https://louthy.github.io/language-ext/LanguageExt.Parsec/index.html) `Parsec` | `Parser` | [Parser monad that can work with any input stream type](https://louthy.github.io/language-ext/LanguageExt.Parsec/index.html) ### New types - Type aliasing Location | Feature | Description ---------|---------|------------ `Core` | `NewType` | [Haskell `newtype` equivalent](https://louthy.github.io/language-ext/LanguageExt.Core/DataTypes/New%20Types/NewType/index.html) i.e: `class Hours : NewType { public Hours(double value) : base(value) { } }`. The resulting type is: equatable, comparable, foldable, a functor, monadic, and iterable `Core` | `NumType` | [Haskell `newtype` equivalent but for numeric types](https://louthy.github.io/language-ext/LanguageExt.Core/DataTypes/New%20Types/NumType/index.html) i.e: `class Hours : NumType { public Hours(double value) : base(value) { } }`. The resulting type is: equatable, comparable, foldable, a functor, a monoid, a semigroup, monadic, iterable, and can have basic artithmetic operations performed upon it. `Core` | `FloatType` | [Haskell `newtype` equivalent but for real numeric types](https://louthy.github.io/language-ext/LanguageExt.Core/DataTypes/New%20Types/FloatType/index.html) i.e: `class Hours : FloatType { public Hours(double value) : base(value) { } }`. The resulting type is: equatable, comparable, foldable, a functor, a monoid, a semigroup, monadic, iterable, and can have complex artithmetic operatio ... ...

近期下载者

相关文件


收藏者