Skip to content

Conversation

@louietan
Copy link

Hi, thanks for this awesome library.

This PR doesn't introduce any new features, just makes existing linq query syntax support complete.

I accidently found the linq query syntax usage from #566.
But the support is incomplete, so I just added the missing implementations (Task/ValueTask/SelectMany etc.),
along with code examples and a brief introduction in the README, so people know this alternative usage exists.

Motivation

Lots of functional languages actually have this syntax sugar, like do-notation in Haskell, for-comprehension in Scala and computation expressions in F#.

C# is not a functional language, but the idea behind the linq syntax is the same, they provide a more concise syntax for the composition of Maybe/Result types without nested function composition or method chaining.

Instead of:

var customer = Email
 	.Create("[email protected]")
	.Bind(email =>
		CustomerName.Create("jsmith").Map(name => new Customer(name, email))
	);

We can use linq query to flatten the code:

var customer =
	from email in Email.Create("[email protected]")
	from name in CustomerName.Create("jsmith")
	select new Customer(name, email);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant