I'll see you again, brother Ron.

A small tribute to brother Ron Topsom.

On Monday (April 2th 2007) afternoon, I lost a brother and a friend.  Ron Topsom was someone that looked after me as I went through a troubled university life (I was always a good kid, but my life went upside down due to events outside of my control).  He made sure that I at least keep turning to the Lord Jesus as well as fellowshipped with me concerning many practical things regarding my personal living with Christ, my studies as a christian, and even working as a single-working believer to be a testimony at work.

In the last few years he has been ill, but it was always good to see him strengthened by the Lord and keep going on.  Sadly, he went to be with the Lord on last Monday.

I miss him already.  I wish I had more time for more fellowship.  It's such a shame, I never have enough time for everything I wanted to do.  I pray when it's my time to go to be with the Lord, I won't have the regret that I have right now.

Thank you Lord for such a pattern of a proper christian.

Get it and Do something with it.

I wrote a much better version of the Get & Do that I'm happy with.  Here's the code below.



// Using this:

private void Form1_Load(object sender, EventArgs e)

{

    new Get<Control>(this.button1, this.button2, this.button3, this.button4)

        .Do(delegate(Control c) { c.Enabled = false; return c; })

        .Do(delegate(Control c) { c.BackColor = Color.Red; return c; });



    new Get<Control>(this.Controls)

        .Do(delegate(Control c) { c.Visible = false; return c; });

}



// The Get class below.

using System.Collections;

using System.Collections.Generic;

namespace GetAndDo
{
    /// <summary>
    /// Get something we want
    /// </summary>
    /// <typeparam name="T"></typeparam>
    class Get<T>
    {
        public List<T> objects;

        /// <summary>
        /// Create a Get wrapper around something we want
        /// </summary>
        /// <param name="getObjs">param array of stuff</param>
        /// <remarks>
        /// Try to design the constructor to be functional and readable.
        /// </remarks>
        public Get(params object[] getObjs)
        {
            objects = new List<T>();
            foreach (object obj in getObjs)
            {
                if (obj is IEnumerable<T>)
                {
                    objects.AddRange((IEnumerable<T>)obj);
                    continue;
                }
                if (obj is IEnumerable)
                {
                    foreach (object obj1 in (IEnumerable)obj)
                    {
                        if (obj1 is T)
                        {
                            objects.Add((T)obj1);
                        }
                    }
                }
                if (obj is T)
                {
                    objects.Add((T)obj);
                }
            }
        }

        /// <summary>
        /// Signature of a delegate for any actions
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// null - filter from result set (filter-operation)
        /// true - include obj in result set
        /// T - include new object in result set (map-operation)
        /// IEnumerable - useful for nesting deep
        /// </returns>
        public delegate object Action(T obj);

        /// <summary>
        /// Run delegate on each element in the current Get wrapper
        /// </summary>
        /// <param name="action">delegate to run</param>
        /// <returns>
        /// New Get wrapper - does not modify original wrapper.
        /// This allows chaining of delegates
        /// </returns>
        public Get<T> Do(Action action)
        {
            List<T> newObjects = new List<T>();
            for (int i = 0; i < objects.Count; i++)
            {
                object result = action(objects[i]);
                if (result == null)
                {
                    continue;
                }
                if (result is T)
                {
                    newObjects.Add((T)result);
                    continue;
                }
                if (result is IEnumerable<T>)
                {
                    newObjects.AddRange((IEnumerable<T>)result);
                }
                if (result is IEnumerable)
                {
                    foreach (object obj1 in (IEnumerable)result)
                    {
                        if (obj1 is T)
                        {
                            objects.Add((T)obj1);
                        }
                    }
                }
                if (true.Equals(result))
                {
                    newObjects.Add(objects[i]);
                    continue;
                }
            }
            return new Get<T>(newObjects.ToArray());
        }
    }
}