Traverse IEnumerable implementation with other data types
public static Maybe<IEnumerable<B>> Traverse<A, B>(this IEnumerable<A> @this, Func<A, Maybe<B>> f) => @this.Fold(Just(Enumerable.Empty<B>()), (a, e) => Just(Append<B>().Curry()).Apply(a).Apply(f(e)));
We already have studied four of the five algebras that are typically used for data structure manipulation:
Monoid -- Fold -- Linq's Aggregate
Functor -- Map -- Linq's Select
Applicative Functor -- Apply -- Linq's does not include this.
Monad -- FlatMap -- Linq's SelectMany...
Represents a class of data structures that conform with the Traversable Functor algebra which is a structure that can be traversed from left to right, performing an action on each element.
Applicative Programming with Effects
The two main methods are:
traverse :: Applicative f =>...
Close on 2 decades ago a few friends of mine & me decided to leave our corporate comfort seats and go solo; starting up a business that focused on providing an advanced level of skills to bolster and/or fast track projects.
Roles also not a close match; used Full Stack Developer.
San Francisco: 50th $258K 75th $325K
London: 50th £102K 75th £129K
Sydney: 50th $187K 75th $236
Proof at least in my case that working for a corporate is no longer a financially sound decision.
Language options appear to have a...
The code for the latest iteration of the pattern matching has been uploaded to github included some bug fixes on the tagged type related to the functor, monad and applicative functor algebras. I have also added a first draft implementation of the Continuation Monad aka "mother of all monads"...
Update to the Tagged Union Type
I've recently wrapped up a simplification of the switch / case for the Tagged Union Types I discussed previously.
Pattern matching over these types previously required a tuple, with the following type signature: params (Func<E, bool> predicate, Action<Tagged<E...
Here's a link to my PHPrelude functional programming repo, which is built off a base of the PHP Vector basic functional combinator framework.
There is however no dependency to Vector -- all the Vector code that I use has been builtin and modified to tie in better with my monadic data type...
Sure, I'll find time this weekend to put up a copy on github; will PM you once it's done.
As for you struggling with where to use it; that's normal for everyone in the beginning & all part of the learning.
The monad can replace almost every parcel of code, because it's an abstraction of very...
I built my own PHP FP library a while back; covering many of the base data types (e.g. Identity, Maybe, Either, Reader, Validation) including many combinators.
You're welcome to a copy of the code if you like?
Example of a Monad's ability to manipulate state?
To illustrate manipulation of state; lets look at the implementation for a monadic filter function.
public static Func<A, IEnumerable<A>> Filter<A>(Predicate<A> p) => a => p(a) ? Enumerable.Empty<A>().Append(a) : Enumerable.Empty<A>();
Abstract behaviour of a Monad
Picking up from the previous post on Monads; let's try to make some sense of the abstract behaviour of the Monad in order to understand why it's a perfect algebra to safely model an imperative computation.
In order to understand why it's function signature is...
My pleasure; happy to hear it's helpful.
Here's another bonus:
I've recently made the decision to open source a new repository incorporating most of the functional API I use in production; shared as a set of Nugets and a github repository. Practical caveat is that only the latest C# language...