Skip to content

AList.partition #89

@fradav

Description

@fradav

Similar to List.partition, adaptively.

A quick and dirt would be :

module AList =
    let partition<'a> (p: 'a -> bool) (l : clist<'a>) =
        let (left,right) = (clist<'a>[],clist<'a>[])
        let addRow (row: 'a) =
            match p row with
            | true  -> transact (fun () -> left.Add row)  
            | false -> transact (fun () -> right.Add row)
            |> ignore
        let removeRow (o: IndexList<'a>) (i : Index) =
            match p o.[i] with
            | true  -> transact (fun () -> left.Remove i)  
            | false -> transact (fun () -> right.Remove i)
            |> ignore
        let processDelta o (i : Index, e : ElementOperation<'a>) =
            match e with
            | Remove -> removeRow o i
            | Set(s) -> addRow s
            |> ignore
        l.AddCallback (fun o c -> c.ToList() 
                                      |> List.iter (processDelta o)) 
        |> ignore
        (left,right)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature to be implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions