Relating to the open-source C# functional framework: language-ext.
Questions tagged [language-ext]
66 questions
5
votes
2 answers
Chain asynchronous operations that return Either using Language-Ext in C#
I am using the Language-Ext library for C# and I am trying to chain asynchronous operations that return an Either type. Let's say that I have three functions that would return an integer if they succeed and a string if the fail, and another function…

Carlos Rodriguez
- 523
- 1
- 5
- 13
4
votes
1 answer
How to convert Task to Task with Language-Ext
Binding tasks together with https://github.com/louthy/language-ext requires tasks with return type (Task<>). Tasks without return type should therefore be converted into Task.
Does anybody know a compact (expression only) way to convert Task…

stb
- 772
- 5
- 15
3
votes
1 answer
How do I get an Option from an Entity Framework Core database call?
Sorry if this is a dumb question, but I'm struggling with Language-Ext, and can't seem to find a neat way to do this.
In non-functional code, I could do something like this...
async Task DoFerretStuff(string id) {
Ferret? ferret = await…

DreamingOfSleep
- 1,208
- 1
- 11
- 23
3
votes
0 answers
async call inside a Map() or Bind() for Option (Functional programming in C#)
Note, if you think this post is long, over half of it is just reference code, for completion
I have started looking at functional programming in C#, mostly through this book
and this tutorial
So I have implemented the Option, with extension method…

Cowborg
- 2,645
- 3
- 34
- 51
3
votes
1 answer
C# LanguageExt - combine multiple async calls into one grouped call
I have a method that looks up an item asynchronously from a datastore;
class MyThing {}
Task> GetThing(int thingId) {...}
I want to look up multiple items from the datastore, and wrote a new method to do this. I also wrote a helper…

Steztric
- 2,832
- 2
- 24
- 43
3
votes
1 answer
How do you write a SelectMany from a Task in F#
I would like to write a SelectMany monadic bind from a Task in F#. How would I write the following C# code which uses language-ext in F#?
Task result = from task in Task.Run(() => 40) select task + 2;

Mike Harris
- 869
- 9
- 21
3
votes
1 answer
how to use applicative validation using languageext?
I am trying to port an example using applicative validation with the teaching-lib LaYumba to LanguageExt.
Here is the LaYumba Code (works as expected):
using System;
using System.Linq;
using FluentAssertions;
using LaYumba.Functional;
using…

draptik
- 470
- 3
- 19
3
votes
1 answer
Object is null even though the object exists and is shown as such in the debugger
I'm writing a Xamarin.Android app and work there with a JSON API, that simply returns an empty string for the data field when it can't find the object in the database. Not a good design, but I can't change it. To check for this eventuality I wrote…

Metalfreak
- 149
- 6
3
votes
2 answers
CustomType on references with FluentNHibernate
I'm using a library called LanguageExt. This library provides some tools to handle functional programming within C# code. I'm also using FluentNHibernate in order to map my domain classes to my database.
When a property is nullable I want to use…

Ephasme
- 286
- 1
- 10
2
votes
1 answer
How do I conditionally call code when using LanguageExt with query syntax?
The code here is an MRE, although very much simplified.
I have a method that takes a transaction and requests a refund. The method looks for the transaction in the database, then calls an external service to request the refund. If the refund were…

Avrohom Yisroel
- 8,555
- 8
- 50
- 106
2
votes
1 answer
Why is my Either-returning method always returning Left, irrespective of what happened?
The use case here is that I have added a method to an Entity Framework DbContext that does some extra work before saving, and then returns an Either depending on the results. A very simplified version of this looks like this...
static async…

Avrohom Yisroel
- 8,555
- 8
- 50
- 106
2
votes
1 answer
LanguageExt - Compiler error using method that returns Task> in a Linq query
Having thought I'd got the hang of this, I'm stuck again!
I'm trying to write a method that takes an encrypted string as a parameter. That string contains the serial number and password of a device that is to be registered in our database, along…

Avrohom Yisroel
- 8,555
- 8
- 50
- 106
2
votes
1 answer
How do I bind a Task> to Either<> with Language-Ext
I have devices (eg mobile phones, payment terminals, etc) that can request a list of cards held in a database. For security, the devices need to authorise themselves, and present their serial number in the JWT token. If any of this doesn't match up,…

Avrohom Yisroel
- 8,555
- 8
- 50
- 106
2
votes
2 answers
How do I return a non-Error type for Left with LanguageExt EitherAsync?
I have a method that looks for a loyalty card in the database, and returns it if it was found and is valid, or an enum value if not. This allows the calling code to switch on the enum value. I want to return an Either

Avrohom Yisroel
- 8,555
- 8
- 50
- 106
2
votes
2 answers
How do I await code inside a method that returns an EitherAsync in LanguageExt?
When using TryAsync in LanguageExt, you can do something like this...
static TryAsync Divide(int n1, int n2) =>
TryAsync(async () => {
// Simulate some async operation that might fail
await Task.Delay(300);
return n1 /…

Avrohom Yisroel
- 8,555
- 8
- 50
- 106