Releases: louthy/language-ext
New functions and memoization improvements
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())
TryOption and standalone 'Unsafe' variants
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() |
First batch of feedback release
Option and Either updates
Some(null)
now doesn't coerce to aNone
, aValueIsNullException
will be thrownSome(Nullable<T>)
supported, will coerce theValue
toSome
ifHasValue
istrue
, otherwise aValueIsNullException
will be thrownRight(Nullable<T>)
/Left(Nullable<T>)
supported, will coerce theValue
toRight
/Left
ifHasValue
is true, otherwise aValueIsNullException
will be thrownSomeUnsafe()
added : AllowsSome(null)
and allows theSome
andNone
branches ofmatch
to returnnull
.RightUnsafe()
/LeftUnsafe()
added : AllowsRight(null)
andLeft(null)
and allows theRight
andLeft
branches of match to returnnull
.- Added
IsUnsafe
toOption<T>
andEither<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...