LanguageExt.Core

LanguageExt.Core Memo

Contents

Sub modules

Extensions
Operators

class Memo <A> Source #

Lazily acquires a value and caches it for repeated use.

Properties

property A Value Source #

Acquired value

If the value is not yet acquired, it will be acquired within Value and cached.

Methods

method Memo<B> Map <B> (Func<A, B> f) Source #

Functor map

method Memo<A> Clone () Source #

Create a clone of the memo (without any cached results). This allows for reacquiring the value.

Parameters

returns

A newly constructed memo structure

method Unit Reset () Source #

Reset the memo. This clears the cached value.

Parameters

returns

Unit

class Memo <F, A> Source #

Makes K〈F, A〉 lazy

This is more of a utility type right now, so it hasn't been fleshed out like other Applicatives

Properties

property K<F, A> Value Source #

Acquired value

If the value is not yet acquired, it will be acquired within Value and cached.

Methods

method Memo<K<F, A>> Lower () Source #

method Memo<F, A> Clone () Source #

Create a clone of the memo (without any cached results). This allows for reacquiring the value.

Parameters

returns

A newly constructed memo structure

method Unit Reset () Source #

Reset the memo. This clears the cached value.

Parameters

returns

Unit

class Memo Source #

Methods

method Memo<G, A> transform <F, G, A> (Memo<F, A> ma) Source #

where F : Natural<F, G>

Natural transformation for memoised higher-kinded structures

Parameters

type F

Original structure

type G

New structure

type A

Bound value type

param ma

Structure to transform

returns

Naturally transformed structure

method Memo<F, A> cotransform <F, G, A> (Memo<G, A> ma) Source #

where F : CoNatural<F, G>

Natural transformation for memoised higher-kinded structures

Parameters

type F

New structure

type G

Original structure

type A

Bound value type

param ma

Structure to transform

returns

Naturally transformed structure

class Prelude Source #

Methods

method Memo<A> memo <A> (Func<A> f) Source #

Returns a Memo〈A〉 that wraps a function. The first call to the resulting Memo〈A〉 will cache the result. Subsequent calls return the cached item.

method Memo<A> memo <A> (A value) Source #

Create a preloaded memo structure with a pure value.

method Memo<F, A> memoK <F, A> (Func<K<F, A>> f) Source #

Returns a Memo〈F, A〉 that wraps a function that yields a higher-kind K〈F, A〉. The first call to the resulting Memo〈F, A〉 will cache the resulting K〈F, A〉. Subsequent calls return the cached item.

NOTE: This does not invoke the K〈F, A〉 computation, it merely caches the construction of the K〈F, A〉. If K〈F, A〉 itself is lazy, then it can be invoked multiple times; this memoisation won't affect that.

method Memo<F, A> memoK <F, A> (A value) Source #

where F : Applicative<F>

Create a preloaded memo structure with a pure value

method Memo<F, A> memoK <F, A> (K<F, A> fa) Source #

where F : Applicative<F>

Create a preloaded memo structure.

method Func<A, B> memo <A, B> (Func<A, B> func) Source #

where A : notnull

Returns a Func〈A, B〉 that wraps func. Each time the resulting Func〈A, B〉 is called with a new value, its result is memoized (cached). Subsequent calls use the memoized value.

Remarks: Thread-safe and memory-leak safe.

method Func<T, R> memoUnsafe <T, R> (Func<T, R> func) Source #

where T : notnull

Returns a Func〈T, R〉 that wraps func. Each time the resulting Func〈T, R〉 is called with a new value, its result is memoized (cached). Subsequent calls use the memoized value.

Remarks: No mechanism for freeing cached values and therefore can cause a memory leak when holding onto the Func〈T, R〉 reference. Uses a ConcurrentDictionary for the cache and is thread-safe

method Seq<T> memo <T> (IEnumerable<T> seq) Source #

Enumerable memoization. As an enumerable is enumerated each item is retained in an internal list, so that future evalation of the enumerable isn't done. Only items not seen before are evaluated.

This minimises one of the major problems with the IEnumerable / yield return pattern by causing at-most-once evaluation of each item.

Use the IEnumerable extension method Memo for convenience.

Although this allows efficient lazy evaluation, it does come at a memory cost. Each item is cached internally, so this method doesn't allow for evaluation of infinite sequences.

Parameters

param seq

Enumerable to memoize

returns

IEnumerable with caching properties