Questions tagged [language-ext]

Relating to the open-source C# functional framework: language-ext.

Language-ext github home page.

66 questions
2
votes
1 answer

How do I bind an async method that returns an Either to an async method that accepts an Option in Language-Ext?

This is a follow-up question to a similar one I asked about binding monads that return different types. I realised after getting a clear answer that I hadn't asked the full question. Rather than amend that question (which does stand on its own so is…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
2
votes
1 answer

How do I bind a method that returns an `Either` to a method that accepts an `Option` in Language-Ext?

For simplicity, I'm presenting a use-case that isn't really realistic (eg role-checking could be done differently, etc), but I'm trying not to confuse the question, so please bear with me. Suppose I want to write a method that accepts an int, and…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
2
votes
1 answer

How to simplify error propagation in C# with Language-Ext, similar to Rust's ? operator?

Is anyone aware of a way to simplify error handling when doing functional programming in C# using the Language-Ext library, similar to the error propagation operator that Rust has? For example, I want to simplify the error handling in the Create…
2
votes
1 answer

Await OptionAsync from Language-ext

I am trying to learn c# Language-ext from Paul Louth. I found the type OptionAsync is quite handy as it combines Tasks and Alternatives into one monad, making it a lot easier to work with both. But I am confused how the await work with OptionAsync.…
DavidY
  • 357
  • 5
  • 15
2
votes
0 answers

How can I replace this foreach loop with something else to achieve a more 'functional programming' approach?

I am trying to write functional code, and I would like to avoid using the foreach loop below. How can I accomplish that? I am using LanguageExt. var errors = ImmutableArray.Create(); var context = new…
Peter Morris
  • 20,174
  • 9
  • 81
  • 146
2
votes
2 answers

In C#, how can I consume an instance of `TryAsync`?

I have the following method: private async Task<(bool, string)> Relay( WorkflowTask workflowTask, MontageUploadConfig montageData, File sourceFile, CancellationToken cancellationToken ) { try { …
Brian Kessler
  • 2,187
  • 6
  • 28
  • 58
2
votes
2 answers

Using a substitute/default return on handling a "failure" when using LanguageExt?

I have a function that returns an Either. On finding a Left return I'd like to substitute in some default object and process that. What's the appropriate pattern, using Language Ext, for doing so? There's a model for this below - myfunc returns an…
Tim Barrass
  • 4,813
  • 2
  • 29
  • 55
2
votes
1 answer

Support for Type Abbreviations / Type Aliases

Please forgive me if I've missed something basic, but does language-ext have support for type abbreviations / type aliases as described here? In one of my projects I've attempted a rudimentary implementation which allows inheriting from the basic…
Damien Sawyer
  • 5,323
  • 3
  • 44
  • 56
2
votes
3 answers

language-ext Task of Either with multiple from clauses

I am learning FP with language-ext and I ran into a problem that I have not been able to overcome. I simplified my code down to this example: using System; using System.Threading.Tasks; using LanguageExt; using static LanguageExt.Prelude; using…
nuester
  • 23
  • 6
2
votes
1 answer

Augment parameter list after partial application in Language-Ext

I'm using language-ext in a C# .NET Core project and I'm able to do partial application on an existing function: Func originalFun = /* ... */; Func partialFun = par(originalFun, paramT1, paramT2, paramT3); Now, I'd like…
superjos
  • 12,189
  • 6
  • 89
  • 134
1
vote
0 answers

How to manage exceptions thrown from Result.Map delegate?

The code for LanguageExt.Common.Result.Map is as follow: [Pure] public Result Map(Func f) => IsFaulted ? new Result(Exception) : new Result(f(Value)); How to manage the scenario where the Func f might throw an…
acmoune
  • 2,981
  • 3
  • 24
  • 41
1
vote
1 answer

Is there a simpler way to do this pipeline with languageext?

I'm trying to grok how to deal with functions that turn one "Either" into many "Either"s and how you then merge those back into a single stream. The following turns one string into many numbers, squaring each and ignoring any errors. Given…
1
vote
1 answer

Language-ext: How to combine synchronous call with async calls?

I'm struggling with the mix of sync. and async calls in language-ext. I've the following simplified example: void Main() { var content = Validate("https://www.google.com") .Bind(Transform) .Bind(FetchUriAsync); } private static…
Moerwald
  • 10,448
  • 9
  • 43
  • 83
1
vote
1 answer

Using Bind in an asynchronous context

I'm using the `language-ext' package for C# in an attempt to make our code more robust, but struggling on how to chain async operations. Consider the following abstract example of a simple class describing a vehicle public class MyVehicle { …
James B
  • 8,975
  • 13
  • 45
  • 83
1
vote
1 answer

Compiler error trying to work out what to put in an Either.Match lambda

I have a situation in which I have a bunch of methods that all require the same code at the beginning. In order to reduce duplication, I want to move that code into a general helper method that would take a lambda parameter for the case-specific…
Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106