Click here to Skip to main content
13,773,358 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 3:42
memberSuper Lloyd19-Mar-18 3:42 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 3:44
mvpRichard Deeming19-Mar-18 3:44 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Super Lloyd19-Mar-18 3:48
memberSuper Lloyd19-Mar-18 3:48 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 4:56
mvpraddevus19-Mar-18 4:56 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 5:09
professionalEddy Vluggen19-Mar-18 5:09 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 5:13
mvpraddevus19-Mar-18 5:13 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 5:18
professionalEddy Vluggen19-Mar-18 5:18 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 6:46
mvpraddevus19-Mar-18 6:46 
Eddy Vluggen wrote:
Like a decorator..

cue Madonna
...touched for the very first time...
Laugh | :laugh: I could not pass that up.

Ignoring the bad joke (if possible) I think your point is really interesting, because it is like a decorator.

Also, in an effort to completely beat this dead horse, how about the following addition?
If, nothing else, the added method has a great name : see SpaceOut.

public static class Helper{
	public static T Tee<T>(
	this T @inVal,
	Action<T> act){
		act(@inVal);
		return @inVal;
	}
	
	public static Byte[] GetBytes( this String @inVal){
		Byte [] outBytes = new Byte[@inVal.Length];
		int loopCount = 0;
		foreach (Char c in @inVal){
			outBytes[loopCount] = Convert.ToByte(c);
			loopCount++;
		}
		return outBytes;
	}
	
	public static String DisplayBytes(this byte[] inBytes){
		String outVal = String.Empty;
		foreach (Byte b in inBytes){
			outVal += Convert.ToString($"{b:D3} ");
		}
		return outVal;
	}
	
	public static String SpaceOut(this string @inVal){
		StringBuilder spacedItem = new StringBuilder();

		foreach (Char c in @inVal){
			spacedItem.Append($" {c}    ");
		}
		Console.WriteLine(spacedItem.ToString());
		return @inVal;
	}
}


Now you can do this:
"What up!"
		.Tee(Console.WriteLine)
		.SpaceOut()
		.GetBytes()
		.DisplayBytes()
		.Tee(Console.WriteLine);


And you will get the following:

What up!
 W     h     a     t           u     p     !    
087   104   097   116   032   117   112   033 


Additionally interesting (or not) is that SpaceOut simply passes the input string along with no change since you only want the input to be printed with the extra spaces but don't want the output altered in this case.

I got a million of 'em! Laugh | :laugh:
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 7:16
professionalEddy Vluggen19-Mar-18 7:16 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 8:23
mvpraddevus19-Mar-18 8:23 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Eddy Vluggen19-Mar-18 9:03
professionalEddy Vluggen19-Mar-18 9:03 
GeneralOFFTOPIC Pin
Nelek19-Mar-18 8:00
protectorNelek19-Mar-18 8:00 
GeneralRe: OFFTOPIC Pin
raddevus19-Mar-18 8:21
mvpraddevus19-Mar-18 8:21 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel20-Mar-18 6:52
professionalSander Rossel20-Mar-18 6:52 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 8:24
mvpraddevus20-Mar-18 8:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming20-Mar-18 8:32
mvpRichard Deeming20-Mar-18 8:32 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus20-Mar-18 9:24
mvpraddevus20-Mar-18 9:24 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Sander Rossel21-Mar-18 2:38
professionalSander Rossel21-Mar-18 2:38 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus21-Mar-18 3:40
mvpraddevus21-Mar-18 3:40 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
Richard Deeming19-Mar-18 9:26
mvpRichard Deeming19-Mar-18 9:26 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 9:40
mvpraddevus19-Mar-18 9:40 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
icemanind19-Mar-18 8:18
membericemanind19-Mar-18 8:18 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 8:27
mvpraddevus19-Mar-18 8:27 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
icemanind19-Mar-18 8:39
membericemanind19-Mar-18 8:39 
GeneralRe: Interesting / strange code picked up from pluralsight training (functional programming) Pin
raddevus19-Mar-18 8:44
mvpraddevus19-Mar-18 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.181119.1 | Last Updated 22 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid