function input = output
var trimmed = ""; if (toTrim != null) { trimmed = toTrim.Trim(); } return trimmed;
var x = 2;
return x;
if toTrim = null then "" else toTrim.Trim()
class Cell { public bool IsAlive { get; set; } public Cell NextState(int livingNeighbors) { if ((IsAlive && livingNeighbors == 2) || livingNeighbors == 3) { return new Cell { IsAlive = true }; } return new Cell { IsAlive = false }; } }
type Cell = DeadCell | LivingCell let nextStateOf cell livingNeighbors = match cell, livingNeighbors with | LivingCell, 2 -> LivingCell | _, 3 -> LivingCell | _ -> DeadCell
public Cell NextState(int livingNeighbors) { return new Cell { IsAlive = (IsAlive && livingNeighbors == 2) || livingNeighbors == 3 }; }
public bool ShouldOfferToGiftWrap() { foreach (var item in Items) { if (item.IsFromWishlist) { return true; } } return false; }
let shouldOfferToWrapGift order = List.exists (fun i -> i.IsFromWishlist) order.Items
public bool ShouldOfferToGiftWrapV2() { // Yeah LINQ! return Items.Any(item => item.IsFromWishlist); }
var shouldOfferToGiftWrap = function(items) { return _(items).some(function(x) { return x.isFromWishlist; }); };
(But please, do not just click "Convert to LINQ"!)
By Keith Pinson
Thinking with functions defined by expressions applied as transformations to a set of data
I am a software developer who is getting into speaking.