by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Paul Louth
    @louthy
    Don’t work with Result and OptionalResult directly, work with the extensions to TryOption (don’t call Try directly); these types are an artefact of the Try types being delegates
    I’m working on a new IO monad prototype to give a slightly more opinionated way to achieve Try semantics https://twitter.com/paullouth/status/1239686656258650113?s=21
    Mattias Homde
    @mhomde
    @louthy I understand, but this is an artifact of a class structure where I keep logging separately in an logging object that inherits from the base class, and logs the exception in the "logging class". Maybe it's an functional-oop frankenstein, but still :) It's quite nice to be able have a method return an OptionalResult and have the logging class above it log it
    Having a lot of logging code in the same class in the same class as the "base code" becomes a bit noisy
    This way I can just have a parent class, and log using like "result.IfFail(exception => Logger?.LogAndReport(exception.Message, exception, LogLevel.Error));"
    Mattias Homde
    @mhomde
    I dunno, I guess you could refactor to log "more functionally" , but it's quite nice to be able separate logging
    just inherit, override and add logging to the optionalresult
    Mattias Homde
    @mhomde
    Weird, I tried to map from a HashSet and got this exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at LanguageExt.TrieSet2.Entries.Update(ValueTuple2 env, K change, UInt32 hash, Sec section)
    at LanguageExt.TrieSet2..ctor(IEnumerable1 items, Boolean tryAdd)
    at LanguageExt.HashSet1..ctor(IEnumerable1 items, Boolean tryAdd)
    at LanguageExt.HashSet1..ctor(IEnumerable1 items)
    at LanguageExt.HashSet1.Map[R](Func2 mapper)
    works if I do ToLst first
    Paul Louth
    @louthy
    @mhomde The reason for the limited API surface of Result and OptionalResult is to discourage use. There's nothing they can do that the Try or TryOption extensions can't. You could call ToOption or ToEither (directly on the Try<A> or TryOption<A>) if you want an optional result value that's a bit more useful.
    @mhomde Re: System.IndexOutOfRangeException - if you have a reproducible error please report it on the Issues with any repro steps. It's hard to tell if this is an actual error from what you've written
    @mhomde btw, if you want to log the errors from the Try* types, you can register with TryConfig.ErrorLogger += YourErrorHandler - it's a bit of an imperative solution, but it's a handy way of getting at the errors without having to build anything into your types
    Mattias Homde
    @mhomde
    oki, will do, thanks!
    Yeah, I guess why Im using OptionalResult, if I've understand things correctly, is that TryOption is lazy , so returning that from an method it hasn't executed yet
    Paul Louth
    @louthy
    You can call ma.Strict() to force evaluation. It then memoises the result, so any further use of it doesn't trigger more IO.
    The conversion to Either or Option(with ToEitherand ToOption) will do a similar thing, but encapsulate the strict value in a non-lazy type.
    Mattias Homde
    @mhomde
    oh cool, thanks!
    Mattias Homde
    @mhomde
    Isn't it weird that when I do Add on a Lst and don't use the return value I don't get an resharper warning? Would've thought the Pure annotation would take care of that
    Sean Farrow
    @SeanFarrow
    Is there a way to match multiple exceptions using ExceptionMatch. The only way I can see to do this is to next Withand Otherwise blocks. Would it be worth having either and AndWith or OrWith to allow this to be done fluently?
    Richard Gibson
    @Richiban
    Does LanguageExt not have a Result<Success, Fail> type? Maybe I'm being blind but I can't find one
    I'm expecting it to behave much like Either but the cases are called Success and Fail instead of Left and Right
    BrainCrumbz
    @BrainCrumbz
    There's a Validation specific data type here, not sure if that suites your scenario
    here in unit tests there's an example usage
    Richard Gibson
    @Richiban
    Thanks for that, I've made use of it!
    I'm suspicious of the fact that partition on an ienumerable walks the sequence twice
    In fact, I now know it does:
    public static (IEnumerable<A> Lefts, IEnumerable<B> Rights) partition<CHOICE, CH, A, B>(
          IEnumerable<CH> ma)
          where CHOICE : struct, Choice<CH, A, B>
        {
          return (Choice.lefts<CHOICE, CH, A, B>(ma), Choice.rights<CHOICE, CH, A, B>(ma));
        }
    Richard Gibson
    @Richiban
    Rather than returning two sequences, shouldn't it return two lists?
    Michael Wolfenden
    @michael-wolfenden
    @louthy did you see this announcement today -> https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/
    Paul Louth
    @louthy
    @michael-wolfenden I did, yes. It looks a little half-baked at the moment. It's a shame it's not a full language integration like F# type-providers. I think it will limit the deployment of code-gen (to > C# 9), so I might swerve it for a while (I obviously do some prototypes, to see if there's benefits over the CodeGeneration.Roslyn route)
    Richard Gibson
    @Richiban
    It's also purely additive, which pretty much guts any usefulness around AOP it might have
    So I'm not really sure what it's for
    Xi Shen
    @davidshen84
    Hi guys. Could anyone help me understand the differences between BindT and BindAsync? From the signature, they look very similar.
    Currently, I have a variable of Task<Either<,>> and I wonder if I should use BindT or BindAsync.
    Paul Louth
    @louthy
    They’re the same, it’s just an accident of trying for consistent naming conventions throughout the library (and that async must be represented with a Task type, which then ‘overlaps’ with the transformer functions). Choose whichever one you like.
    BrainCrumbz
    @BrainCrumbz
    There's this relatively old issue, but it still has quite a bit of info on BindT and other Transformers: louthy/language-ext#207
    Jeramy Rutley
    @jrutley

    Hello there. Is there something I'm missing? I see in the documentation code like

    Right<Exception, ADUser>(ADUser.New("test user")).AsTask();

    but when I try anything similar, I get the following error:
    "The name 'Right' does not exist in the current context"

    AFAIK I'm using the latest version of language-ext (3.4.x), and I think I've installed all the NuGet packages in this particular project

    Paul Louth
    @louthy
    @jrutley using static LanguageExt.Prelude - many of the functions are in the Prelude static class and need bringing in before you can use them. You could also use them directly: Prelude.Right(...
    The Getting started section should cover it
    Jeramy Rutley
    @jrutley
    Thanks!
    Mattias Homde
    @mhomde
    Maybe I'm missing something, but why is doing list pattern matching on a Lst<T> giving a Seq<T> in the lamba? Technical limitation?
    Stefan Bertels
    @StefanBertels
    .Match currently is an extension function defined on IEnumerable<T>. I think there could be a special version for Lst<T> if there is some need (maybe advantage using same memory structure?)
    Paul Louth
    @louthy
    @mhomde Performance. Constructing a new Lst for the tail would be expensive. Seq however can take an IEnumerable (the Lst) and provide a tail very quickly.
    4 replies
    Stefan Bertels
    @StefanBertels
    Hi Paul, IIRC the last advice was to use Seq instead of Lst anyway. Is this correct?
    Paul Louth
    @louthy
    Yep, Seq does everything Lst does, but faster. The only thing Seq doesn't support is random insertion and deletion (at a random index)
    Stefan Bertels
    @StefanBertels
    Mayby @mhomde assumed that Lst is backed by a Cons thing (head + tail) but this changed some releases before...
    Paul Louth
    @louthy
    I don't think Lst was ever a cons list. Although, lang-ext is 5 years old now, so maybe i've just forgotten. It is an AVL tree (sorted by the index of the entry). Seq however is array backed, which doubles in size when the backing array is filled. This has massive data locality benefits, which leads to big performance gains.
    Stefan Bertels
    @StefanBertels
    Ah, ok. Thanks for clarifying.
    (I probably confused this with Seq which had such a head/tail implementation IIRC -- but I stop speculating now...)
    Paul Louth
    @louthy
    I suspect it's because it supported the cons operation, but I don't think it was ever a cons list: i.e. a type of Lst<A> = Empty | Cons(A, Lst<A>)
    Sean Farrow
    @SeanFarrow
    I have a base class deriving from Record and wondered whether using attributes it is possible to prevent any class deriving from this base class changing what is compared within equality operations or what is returned when GetHashCode or ToString is called.