Skip to content

Releases: louthy/language-ext

New functions and memoization improvements

22 Nov 02:43
Compare
Choose a tag to compare

New functions for Option, OptionUnsafe, TryOption:

  • bind
  • map
  • exists
  • fold
  • count
  • forall
  • ToList
  • ToArray

New functions in List and Map:

  • iter
  • forall
  • mapi
  • addRange

Improved memoization:

  • Uses a WeakDictionary from the ch.codeplex.com library, this removes the possibility of memory-leaks whilst maintaining the compositional nature of Func<T,R>. In a unit-test memoizing 0 -> Int32.MaxValue strings, the NUnit runner never jumped above 45mb.
  • memo() must use a reference type for R, so the old memoization function is kept for completeness, except it's now called memoUnsafe, with warnings in the comments about potential memory leaks.

Breaking changes:

  • each() has been renamed iter()
  • AsEnumerableOne() renamed AsEnumerable() and removed the infinite variants (originally called AsEnumerable())

https://www.nuget.org/packages/LanguageExt/

TryOption and standalone 'Unsafe' variants

21 Nov 12:48
Compare
Choose a tag to compare

New TryOption<T> type for catching all three possible outputs of a function: value, null, Exception. With three branches in Match: Some|None|Fail.

Option<T> and Either<R,L> have been split in to Option<T>, OptionUnsafe<T>, Either<R,L> and EitherUnsafe<R,L>. The 'unsafe' variants are for the cases where null is actually a valid Some value. They are only 'unsafe' because the of this reason.

Construction of OptionUnsafe<T> and EitherUnsafe<R,L> is done using SomeUnsafe(value), RightUnsafe(value), LeftUnsafe(value). Matching is done using matchUnsafe(...) and failureUnsafe.

This is much more declarative, and will clearly bias the programmer toward the safe types, only opting out when they absolutely need null as a valid value.

Breaking change: set becomes setItem.

New prelude functions Description
stack<T>() Create an IImmutableStack
set<T>() Create an IImmutableHashSet
array<T>() Create an ImmutableArray
queue<T>() Create an IImmutableQueue
New List functions Description
freeze Takes an IEnumerable and turns it into an IImmutableList
zip Wrapper for Enumerable.Zip
length Wrapper for IImmutableList.Count()
New Map functions Description
length Wrapper for IImmutableDictionary.Count()

https://www.nuget.org/packages/LanguageExt/

First batch of feedback release

20 Nov 16:47
Compare
Choose a tag to compare
Pre-release

Option and Either updates

  • Some(null) now doesn't coerce to a None, a ValueIsNullException will be thrown
  • Some(Nullable<T>) supported, will coerce the Value to Some if HasValue is true, otherwise a ValueIsNullException will be thrown
  • Right(Nullable<T>)/Left(Nullable<T>) supported, will coerce the Value to Right/Left if HasValue is true, otherwise a ValueIsNullException will be thrown
  • SomeUnsafe() added : Allows Some(null) and allows the Some and None branches of match to return null.
  • RightUnsafe()/LeftUnsafe() added : Allows Right(null) and Left(null) and allows the Right and Left branches of match to return null.
  • Added IsUnsafe to Option<T> and Either<R,L>

I'm considering whether the 'unsafe' variants should return a OptionUnsafe<T> and EitherUnsafe<R,L> to make it explicit that the Some,Right and Left branches could have null and that's a valid result. I'm inviting feedback...