Skip to content

Let extension method #15

@Simplifier

Description

@Simplifier
// Use .let and forget weird helper methods
val data = DataPoint(1, 22.1, DataPoint(2, 22.8))
val result = data.child?.child?.
            let { toFahrenheit(it.celsius) } ?: Double.MIN_VALUE

Let extension could be easily written in c# like this

static class Ext
{
    public static TR Let<T, TR>(this T obj, Func<T, TR> func) => func(obj);
}

And then c# example would be pretty similar to kotlin's

var data = new DataPoint(1, 22.1, new DataPoint(2, 22.8));
var result = data.Child?.Child?
    .Let(p => ToFahrenheit(p.Celsius)) ?? double.MinValue;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions