Fluent Collection NOT !

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.

The title of this post might be a little misleading. I am still having Adventures in Creating Fluent Interfaces. I wanted to be able to find People with Names that did NOT Contain some text. I started of by adding a new function NotContains but I quickly realized that I would be doubling my functions. The answer was so simple and felt so good. I had already centralized by code that evaluated the function so I just needed to add an optional parameter boolean for tracking if I wanted the standard function or the ‘Not’ version. I added a variable to hold it. I modified the GetList function to use the new variable. Finally I created a new “Not’ function that returns the same FluentComparableList but passes in the boolean as true. Here is the modified FluentComparableList code sample:

 

Public Class FluentComparableList(Of ListType As {IList, New}, ItemType, ParamaterType As IComparable)
    Public InternalList As ListType
    Public InternalFunction As Func(Of ItemType, ParamaterType)
    Public useNot As Boolean


    Sub New(ByRef list As ListType, ByVal _Func As Func(Of ItemType, ParamaterType), Optional ByVal _Not As Boolean = False)
        InternalList = list
        InternalFunction = _Func
        useNot = _Not
    End Sub

    Public Function [Not]() As FluentComparableList(Of ListType, ItemType, ParamaterType)
        Return New FluentComparableList(Of ListType, ItemType, ParamaterType)(InternalList, Function(s) InternalFunction(s), True)
    End Function

    Public Function GetNewList(ByRef _Func As Func(Of ItemType, Boolean))
        GetNewList = New ListType
        For Each item In InternalList
            If useNot Then
                If Not _Func(item) Then GetNewList.Add(item)
            Else
                If _Func(item) Then GetNewList.Add(item)
            End If
        Next
    End Function

    Public Function Greater(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) > 0)
    End Function

    Public Function Lesser(ByVal i As Integer) As ListType
        Return GetNewList(Function(item) InternalFunction(item).CompareTo(i) < 0)
    End Function
etc..

I do even fewer changes to the FluentStringList. I just pass the boolean on to the base class. I have to shadow the Not class in the base class because I want to return a FluentStringList instead of the FluentStringList that comes out of the base. Now I have the ability to ‘Not’ everything. I can find out how many people don’t have ‘tle’ in their name with:

People.Name.Not.Contains('tle').count

Here are some tests:

Dim target As PersonList

Public Sub MyTestInitialize()
    target = New PersonList
    target.Add(New Person("Bentley", "1/1/1973"))
    target.Add(New Person("Joe", "2/1/1992"))
    target.Add(New Person("Jimmy", "3/1/2005"))
    target.Add(New Person("Karla", "4/1/1984"))
    target.Add(New Person("Cameron", "5/1/1950"))
End Sub


Public Sub FindAll_not_StartsWith()
    Dim Found = target.Name.Not.StartsWith("J")

    Assert.AreEqual(3, Found.Count)
    Assert.AreEqual(5, target.Count, "Has no side-effects")
End Sub


Public Sub BigTest()
    Dim Found = target.Name.Not.EndsWith("y").Name.Not.IndexOf("e").Not.Greater(1)

    Assert.AreEqual(1, Found.Count)
    'Only Karla should match this one
End Sub

I wouldn’t suggest using that many ‘Not’s in production code. It’s amazing how much power we got from so little code. Tell me what you think of this modification in the comments below.