Kotlin.ScopeFunctions 0.6.0

dotnet add package Kotlin.ScopeFunctions --version 0.6.0
                    
NuGet\Install-Package Kotlin.ScopeFunctions -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kotlin.ScopeFunctions" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kotlin.ScopeFunctions" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="Kotlin.ScopeFunctions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kotlin.ScopeFunctions --version 0.6.0
                    
#r "nuget: Kotlin.ScopeFunctions, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kotlin.ScopeFunctions@0.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kotlin.ScopeFunctions&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=Kotlin.ScopeFunctions&version=0.6.0
                    
Install as a Cake Tool

Kotlin.ScopeFunctions

Use Kotlin's Scope Functions in .NET

Like LINQ for single values, Scope Functions are a powerful way to write code that is more declarative and reads like the flow of information through your program.

Installation

The package is available from nuget.org as Kotlin.ScopeFunctions

Or, you can run install-package Kotlin.ScopeFunctions from within your IDE

Getting started

Most .NET developers are very comfortable with using chains of LINQ extension methods to process data in a pipeline that reads fluently from left to right, describing how data maps from source to result through a series of transformation steps.

Typically this is easier to read than the same thing written as nested method calls, since developers are usually happier to read a flow from left to right than to unpick a nested set of method calls.

So, what if you could do the same thing with single values as you can with enumerables?

That's where Kotlin's scope functions come in. They allow you to use an extension method that takes the source object as the argument to a supplied delegate, just like LINQ functions allow you to use an extension method that takes the elements of the source sequence as arguments to a supplied delegate.

This simple library re-implements Kotlin Scope Functions so that you can use the same pattern to improve your C# code.

They come in three flavours:

  • Firstly Let() which takes the source object and returns the result of calling the delegate. This is like a scalar version of Enumerable.Select() and is useful for fluently mapping an object through a transformation, or a series of transformations.
  • Secondly Also() which takes the source object and calls the supplied delegate on the object, but returs the original object. This is like a scalar version of List<>.ForEach(). This is useful for applying an action to an object (perhaps part of its initialisation) without needing to declare a local variable specifically for the purpose.
  • Finally, TakeIf() and TakeUnless() which apply a predicate to the source object, returning either the object or default(T), depending on ther result and the sense of If / Unless. This is like a scalar version of Enumerable.Where() and is useful alongside the null-conditional operator ?. to allow a subsequent method call to execute only if a condition is met.

LetAsync() and AlsoAsync are also available for async use cases

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0 103 2/25/2026
0.5.0 110 2/24/2026
0.4.0 126 2/23/2026
0.3.0 115 2/13/2026
0.2.0 110 2/13/2026
0.1.0 94 2/13/2026